XSD <anyAttribute> అంశం

<anyAttribute> ఎలమెంట్ మాకు, షేమా ద్వారా నిర్వచించబడని గుణాల ద్వారా XML డాక్యుమెంట్ను విస్తరించడానికి సామర్ధ్యం కలిగిస్తుంది!

<anyAttribute> ఎలమెంట్

<anyAttribute> ఎలమెంట్ మాకు, షేమా ద్వారా నిర్వచించబడని గుణాల ద్వారా XML డాక్యుమెంట్ను విస్తరించడానికి సామర్ధ్యం కలిగిస్తుంది!

ఈ ఉదాహరణ "family.xsd" పేరు కలిగిన XML షేమా యొక్క ఒక భాగం నుండి వచ్చింది. ఇది "person" ఎలమెంట్ కోసం ఒక ప్రకటనను మాకు చూపిస్తుంది. <anyAttribute> ఎలమెంట్ ద్వారా, మేము "person" ఎలమెంట్ కు ఏదైనా సంఖ్యలో గుణాలను జోడించవచ్చు:

<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>

ఇప్పుడు, మేము "gender" అంశం ద్వారా "person" అంశాన్ని విస్తరించడానికి ఆశిస్తున్నాము. ఈ విధంగా చేయవచ్చు, కానీ ఈ schema రచయిత ఏ మాట్లాడని "gender" అంశాన్ని పేర్కొనేలా చేయలేదు.

ఈ schema ఫైలును చూడండి, "attribute.xsd" అనే పేరుతో:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.codew3c.com"
xmlns="http://www.codew3c.com"
elementFormDefault="qualified">
<xs:attribute name="gender">
  <xs:simpleType>
    <xs:restriction base="xs:string">
      <xs:pattern value="male|female"/>
    </xs:restriction>
  </xs:simpleType>
</xs:attribute>
</xs:schema>

ఈ XML ("Myfamily.xml" అనే పేరుతో), "family.xsd" మరియు "attribute.xsd" అనే వివిధ schema ల భాగాలను వాడుతుంది:

<?xml version="1.0" encoding="ISO-8859-1"?>
<persons xmlns="http://www.microsoft.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:SchemaLocation="http://www.microsoft.com family.xsd
http://www.codew3c.com attribute.xsd">
<person gender="female">
<firstname>Jane</firstname>
<lastname>Smith</lastname>
</person>
<person gender="male">
<firstname>David</firstname>
<lastname>Smith</lastname>
</person>

上面这个 XML 文件是有效的,这是因为 schema "family.xsd" 允许我们向 "person" 元素添加属性。

<any> మరియు <anyAttribute> అదే విధంగా విస్తరణీయ డాక్యుమెంట్స్ తయారు చేయడానికి ఉపయోగపడతాయి! వాటివల్ల డాక్యుమెంట్స్ ముఖ్యమైన XML షేమాలో పేర్కొనబడని అదనపు అంశాలను చేర్చగలవు.