Monday, March 31, 2014

Element with embedded html schema

An incoming document will have a text element, but embedded in that text may or may not be html. The html may or may not have multiple nodes. Since the schema will treat html tags as elements, it is necessary for us to handle this case as if we were receiving xml elements.

To create the xsd schema, it was necessary to use the xs:any element.

So the schema looks like this:

<xs:element minOccurs="0" maxOccurs="1" name="Element">
<xs:complexType mixed="true">
  <xs:sequence>
 <xs:any minOccurs="0" maxOccurs="unbounded" processContents="skip"/>
  </xs:sequence>
</xs:complexType>
</xs:element>

The mixed attribute on xs:complexType tells us that the element can contain text as well as elements. Setting the minOccurs and maxOccurs on the xs:any element tells us that there may not be any embedded elements (in this case html) and there may be an unbounded upper limit. The processContents="skip" will not validate against a schema, allowing us to have any elements.

http://msdn.microsoft.com/en-us/library/aa547371.aspx