XSD <anyAttribute>
Element
The <anyAttribute>
element allows us to extend XML documents with attributes not specified by the schema!
The <anyAttribute>
element allows us to extend XML documents with attributes not specified by the schema!
The following example is a snippet from an XML schema named "family.xsd". It shows a declaration for the "person" element. By using the <anyAttribute>
element, we can add any number of attributes to the "person" element:
Now, we want to extend the "person" element with a "gender" attribute. In this case, we can do so even though the schema author never declared any "gender" attribute.
Please refer to this schema file, named "attribute.xsd":
The following XML (named "Myfamily.xml") uses components from different schemas, "family.xsd" and "attribute.xsd":
The above XML file is valid because the schema "family.xsd" allows us to add attributes to the "person" element.
Both <any>
and <anyAttribute>
can be used to create extensible documents! They enable documents to include additional elements not declared in the main XML schema.