XSD <any> ÔªËØ

<any> ÔªËØÊ¹ÎÒÃÇÓÐÄÜÁ¦Í¨¹ýδ±» schema ¹æ¶¨µÄÔªËØÀ´ÍØÕ¹ XML Îĵµ£¡

<any> ÔªËØ

<any> ÔªËØÊ¹ÎÒÃÇÓÐÄÜÁ¦Í¨¹ýδ±» schema ¹æ¶¨µÄÔªËØÀ´ÍØÕ¹ XML Îĵµ£¡

ÏÂÃæÕâ¸öÀý×ÓÊÇ´ÓÃûΪ "family.xsd" µÄ XML schema ÖÐÒýÓÃµÄÆ¬¶Î¡£ËüչʾÁËÒ»¸öÕë¶Ô "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.w3school.com.cn"
xmlns="http://www.w3school.com.cn"
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 Öеijɷ֣¬"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.w3school.com.cn children.xsd">

<person>
<firstname>David</firstname>
<lastname>Smith</lastname>
<children>
  <childname>mike</childname>
</children>
</person>

<person>
<firstname>Tony</firstname>
<lastname>Smith</lastname>
</person>

</persons>

ÉÏÃæÕâ¸ö XML ÎļþÊÇÓÐЧµÄ£¬ÕâÊÇÓÉÓÚ schema "family.xsd" ÔÊÐíÎÒÃÇͨ¹ýÔÚ "lastname" ÔªËØºóµÄ¿ÉÑ¡ÔªËØÀ´À©Õ¹ "person" ÔªËØ¡£

<any> ºÍ <anyAttribute> ¾ù¿ÉÓÃÓÚÖÆ×÷¿ÉÀ©Õ¹µÄÎĵµ£¡ËüÃÇʹÎĵµÓÐÄÜÁ¦°üº¬Î´ÔÚÖ÷ XML schema ÖÐÉùÃ÷¹ýµÄ¸½¼ÓÔªËØ¡£

VUE