xsd <any> xsd element substitution
the <anyAttribute> element gives us the ability to extend an XML document through attributes not defined by the schema. <anyAttribute> Elements
The <anyAttribute> element gives us the ability to extend an XML document through attributes not defined by the schema.
The following example is a fragment from an XML schema named "Family.xsd". It shows us a declaration for the "person" element. By using the <anyAttribute> element, we can add any number of attributes to the "person" element:
<xs:element name= "Person" >
<xs:complexType>
<xs:sequence>
<xs:element name= " FirstName "type=" xs:string "/>
<xs:element name=" LastName "type=" xs:string "/>
</xs:sequence >
<xs:anyAttribute/>
</xs:complexType>
</xs:element>
Now, we want to extend the "person" element with the "gender" attribute. In this case we can do this even if the author of the schema never declares any "gender" attributes.
Please see this schema file, named "Attribute.xsd":
<?xml version= "1.0" encoding= "iso-8859-1"?> <xs:schema
xmlns:xs= "Http://www.w3.org/2001/XMLSchema"
targetnamespace= "http://www.w3school.com.cn"
xmlns= "http://www.w3school.com.cn
" elementformdefault= "qualified" >
<xs:attribute name= "Gender" >
<xs:simpleType>
<xs: Restriction base= "xs:string" >
<xs:pattern value= "Male|female"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:schema>
The following XML (named "Myfamily.xml") uses elements from different schemas, "family.xsd" and "attribute.xsd":
<?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.w3school.com.cn attribute.xsd ">
<person gender=" female ">
<firstname>jane</ firstname>
<lastname>Smith</lastname>
</person>
<person gender= "Male" >
<firstname>David</firstname>
<lastname>Smith</lastname>
</person>
</persons>
The above XML file is valid because the schema "Family.xsd" allows us to add attributes to the "person" element.
<any> and <anyAttribute> can be used to make extensible documentation. They make the document capable of containing additional elements that are not declared in the main XML schema.