Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

XML Schema anyAttribute Element

XSD Element


The element gives us the ability to extend an XML document with attributes not specified by the schema!


The element gives us the ability to extend an XML document with attributes not specified by the schema!

The following example is a snippet from an XML schema named "family.xsd". It shows us a declaration for the "person" element. By using the element, we can add any number of attributes to the "person" element:

  xs:complexType

    xs:sequence

     

     

   

    xs:anyAttribute/

 

Now, we want to extend the "person" element with a "gender" attribute. We can do this in this case even if the author of this schema never declared any "gender" attribute.

Look at this schema file, named "attribute.xsd":

targetNamespace="http://www.w3schools.com"

xmlns="http://www.w3schools.com"

elementFormDefault="qualified">

  xs:simpleType

   

     

   

 

The following XML (named "Myfamily.xml") uses components from different schemas, "family.xsd" and "attribute.xsd":

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xsi:SchemaLocation="http://www.microsoft.com family.xsd

http://www.w3schools.com attribute.xsd">

  Hege

  Refsnes

  Stale

  Refsnes

The XML file above is valid because the schema "family.xsd" allows us to add attributes to the "person" element.

and Both can be used to make extensible documents! They give documents the ability to contain additional elements not declared in the main XML schema.