The < any > element gives us the ability to expand XML documents through elements that are not specified by schema! The < any > element gives us the ability to expand XML documents through elements that are not specified by schema! The following example is a snippet referenced from a XML schema named “family.xsd”. It shows a declaration for the “person” element. By using the < any > element, we can extend the content of “person” with any element (after < lastname >): Now we want to use the “children” element to extend the “person” element. We can do this in this case, even if the author of the above schema does not declare any “children” elements. Please look at this schema file, named “children.xsd”: The following XML file (named “Myfamily.xml”) uses components from two different schema, “family.xsd” and “children.xsd”: The above XML file is valid because the schema “family.xsd” allows us to extend the “person” element with an optional element after the “lastname” element. Both < any > and < anyAttribute > can be used to make extensible documents! They give the document the ability to contain additional elements that are not declared in the main XML schema.< any > element ¶
<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>
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">
<xs:element name="children">
<xs:complexType>
<xs:sequence>
<xs:element name="childname" type="xs:string"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
<?xml version="1.0" encoding="ISO-8859-1"?>
<persons xmlns="http://www.microsoft.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.microsoft.com family.xsd
http://www.w3schools.com children.xsd">
<person>
<firstname>Hege</firstname>
<lastname>Refsnes</lastname>
<children>
<childname>Cecilie</childname>
</children>
</person>
<person>
<firstname>Stale</firstname>
<lastname>Refsnes</lastname>
</person>
</persons>