How to use XSD <anyAttribute> Element in XML

In this article I am going to explain about XSD <anyAttribute> in XML.
  • 3310

XSD The  <anyAttribute>  Element in XML

XSD <any> Element as such type of element in XML by which we can extend XML document with Attribute. Its not specified by the Schema.

Example

In following example we have XML scheme name is Emp.xsd its show the declaration of "Employee" element by using the <anyAttribute>  elemet. We can add any number of attribute to "Employee" element.

<xs:element name="Employee">

  <xs:complexType>

    <xs:sequence>

      <xs:element name="Fname" type="xs:string"/>

      <xs:element name="Address" type="xs:string"/>

    </xs:sequence>

    <xs:anyAttribute/>

  </xs:complexType>

</xs:element>

 

In this Example we have another schema doce.xsd its show the declaration of "marriedStatus" element.

 

<?xml version="1.0" encoding="iso-8859-1"?>

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"

targetNamespace="https://dotnetheaven.com"

xmlns="http://https://dotnetheaven.com"

elementFormDefault="qualified">

 

  <xs:attribute name="marriedStatus">

    <xs:simpleType>

      <xs:restriction base="xs:string">

        <xs:pattern value="married |Unmarried"/>

      </xs:restriction>

    </xs:simpleType>

  </xs:attribute>

 

</xs:schema>

 

In this example we have another schema Company.xsd that used two different schema component.

 

<?xml version="1.0" encoding="ISO-8859-1"?>

 

<Employee xmlns="http://www.microsoft.com"

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

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

https://dotnetheaven.com doce.xsd">

 

  <Employee gender="Married">

    <Fname>jown</Fname>

    <Address>Delhi</Address>

  </Employee>

 

  <Employee gender="Unmarried">

    <Fname>Jown</Fname>

    <Address>Delhi</Address>

  </Employee>

 

</Employee>

Further Readings

You may also want to read these related articles: here
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

 

© 2020 DotNetHeaven. All rights reserved.