XSD anyAttribute Element

To extend the XML document with attributes not specified by the schema, the <anyAttribute> element is used.

The <anyAttribute> Element:

To make EXTENSIBLE documents, i.e., to allow documents to contain additional elements that are not declared in the main XML schema, the <any> and <anyAttribute> elements are used.

Example:


  
    
      
      
    
    
  

Explanation:

In the above example, we are displaying a fragment from an XML schema called “friend.xsd”, declaring the “student” element. The number of attributes to the “student” element can be increased by using the <anyAttribute> element.

attribute.xsd:





  
    
      
    
  



Explanation:

In the above example, we are extending the “student” element with the “dresscolor” attribute, even when the author of the above schema never declared any “dresscolor” attribute.

Example:






  Tom
  Jonas



  Jack
  Davis



Explanation:

In the above example, we are creating the “Myfriend.xml” file to use the components from two different schemas; “friend.xsd” and “attribute.xsd”. Now, since the schema “friend.xsd” allows us to add an attribute to the “student” element, the XML file Myfriend.xml is valid.

Please follow and like us:
Content Protection by DMCA.com