Overview
The XSD <any> element is very useful while designing generic schema or a schema to contain something unexpected/undefined or set of defined XML or elements.
The <any> element provides a way to keep/contain XML element which is not defined in the schema. For more details and example, Please read here :
Problem
There is a requirement to design a schema which should be generic in nature to contain any undefined type of XML. For example the following XML should be able to contain any XML in the <Details> element. As in the below example it contains <feedtext> element
The XM: should be able to contain any other XML in the <Details> as below a different input:
As in the above input XML , it contains <feedtextfromsite1>
Solution
To cater the above requirement we have to use <any> element in our schema . As defined in the page here, If a element is defined as <any> It can contain any other XML which is not defined in the schema.
Code
We will start by creating a schema using BizTalk Schema editor , Below are few steps:
- Create the Root Element and name it “MyBlogRssFeeds”
- Insert a record and rename it to “Header”
- Insert a record below “Header”
- Insert a record below root element and name it “Details”
- Insert <any> element by Right Click on <Details>, then select “Insert Schema Node” then select “Any Element” .
- After this the schema should look like below:
And with this I was able to create a generic schema and was able to validate my XML.
And One More Thing!!
Please pay attention of the properties of <Any> element: It should look like below:
The property “Process Contents” should be set to “Skip” . Because of course we do not want the XML engine to validate the structure of this element.
the definition of this property is below from this page :
“Indicates how XML from other namespaces (introduced by the any element in a content model) should be validated. The value for this attribute may be one of ‘strict’ (the processor must retrieve the schema declaration associated with the namespace and validate the XML); ‘lax’ (the processor should attempt to validate the XML against its schema); and ‘skip’ (the processor should not attempt to validate the XML) “
Thanks for reading!