XML Schema anyAttribute Element | Rookie Tutorial
Rookie Tutorial -- Learning is not just technology, but also dreams!
- Home
- HTML
- JavaScript
- CSS
- Vue
- React
- Python3
- Java
- C
- C++
- C#
- AI
- Go
- SQL
- Linux
- VS Code
- Bootstrap
- Git
- Local Bookmarks
XML Schema Tutorial
XML Schema TutorialIntroduction to XML SchemasWhy use XML Schema?How to use XML SchemaXML schema elementXSD Simple ElementsXML Schema AttributesXML Schema Restrictions / FacetsXML Schema Complex ElementsXML Schema Complex Empty ElementsXML Schema Complex Types β Elements OnlyXML Schema Complex Elements β Text OnlyXML Schema Complex Types β Mixed ContentXML Schema IndicatorsXML Schema any ElementXML Schema anyAttribute ElementXML Schema Element SubstitutionXML Schema ExamplesXML Schema String Data TypesXML Schema Date/Time Data TypesXML Schema Numeric Data TypesXML Schema Miscellaneous Data TypesXML EditorXML Schema SummaryXML Schema Reference Manual
XML Schema any Element XML Schema Element SubstitutionExplore Deeply
Programming
Network Services
Web Design and Development
Script Languages
Programming Languages
Search
Development Tools
Software
Web Service
Computer Science
XSD <anyAttribute> Element
The <anyAttribute> element gives us the ability to extend XML documents with attributes that are not specified by the schema!
The <anyAttribute> element gives us the ability to extend XML documents with attributes that are not specified by the schema!
The following example is a fragment from an XML schema called "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 a "gender" attribute. In this case, we can do it even though the author of this schema never declared any "gender" attribute.
Look at 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.w3schools.com"
xmlns="http://www.w3schools.com"
elementFormDefault="qualified">
<xs:attribute name="gender">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="male|female"/>
YouTip