XSD 元素
<any> ఎలమెంట్ మాకు షేమా ద్వారా నిర్వచించబడని ఎలమెంట్లను ఉపయోగించడం ద్వారా XML డాక్యుమెంట్ను విస్తరించడానికి సామర్ధ్యం కలిగిస్తుంది!
<any> ఎలమెంట్
<any> ఎలమెంట్ మాకు షేమా ద్వారా నిర్వచించబడని ఎలమెంట్లను ఉపయోగించడం ద్వారా XML డాక్యుమెంట్ను విస్తరించడానికి సామర్ధ్యం కలిగిస్తుంది!
ఈ ఉదాహరణ "family.xsd" పేరు కలిగిన XML షేమా నుండి సంకేతం. ఇది "person" ఎలమెంట్ కోసం ఒక ప్రకటనను ప్రదర్శిస్తుంది. <any> ఎలమెంట్ ద్వారా, మేము <lastname> తర్వాత ఏ ఎలమెంట్ ద్వారా "person" కంటెంట్ ను విస్తరించవచ్చు:
<xs:element name="person"> <xs:complexType> <xs:sequence> <xs:element name="firstname" type="xs:string"/> <xs:element name="lastname" type="xs:string"/> <xs:any minOccurs="0"/> </xs:sequence> </xs:complexType> </xs:element>
ఇప్పుడు, మేము "children" ఎలమెంట్ ను "person" ఎలమెంట్ ను విస్తరించడానికి కావాలి. ఈ పరిస్థితిలో మేము ఇలా చేయవచ్చు, అయితే ఈ schema రచయిత కాకపోయినా "children" ఎలమెంట్ ను పేర్కొనేలా లేదు.
ఈ schema ఫైలును చూడండి, పేరు "children.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:element name="children"> <xs:complexType> <xs:sequence> <xs:element name="childname" type="xs:string" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema>
ఈ XML ఫైలు (పేరు "Myfamily.xml") రెండు వేర్వేరు schema లోని అంశాలను వాడుతుంది, "family.xsd" మరియు "children.xsd":
<?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 children.xsd"><firstname>David</firstname> Smith <children> <childname>mike</childname>Tony Smith
上面这个 XML 文件是有效的,这是由于 schema "family.xsd" 允许我们通过在 "lastname" 元素后的可选元素来扩展 "person" 元素。