Tag Archives: any

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! 🙂