XML Schemas and ANY

I was tasked with creating an XML schema with extensibility, both from the application perspective and from the “we don’t have the requirements finished yet” perspective.

My solution was a simple key-value pair approach within a generic array. It could work:
<xs:element name="person">
 <xs:complexType>
  <xs:sequence>
   <xs:element name="attrKey" type="xs:string"/>
   <xs:element name="attrVal" type="xs:string"/>
  </xs:sequence>
 </xs:complexType>
</xs:element>

But then someone mentioned the use of the “any” element. I had never heard of it.

Turn out you can make a smarter extensible document by using the any element (from http://www.w3schools.com/schema/schema_complex_any.asp):

<xs:element name="person">
 <xs:complexType>
  <xs:sequence>
   <xs:element name="firstname" type="xs:string"/>
   <xs:element name="lastname" type="xs:string"/>
   <xs:any minOccurs="0"/>
  </xs:sequence>
 </xs:complexType>
</xs:element>

Boy that’s smart stuff. I like it! Now, to just see if we can implement it in time! đŸ™‚

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: