XSD <anyAttribute> ÔªËØ

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

<anyAttribute> ÔªËØ

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

ÏÂÃæµÄÀý×ÓÊÇÀ´×ÔÃûΪ "family.xsd" µÄ XML schema µÄÒ»¸öƬ¶Î¡£ËüΪÎÒÃÇչʾÁËÕë¶Ô "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.w3school.com.cn"
xmlns="http://www.w3school.com.cn"
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"£©£¬Ê¹ÓÃÁËÀ´×Ô²»Í¬ schema µÄ³É·Ö£¬"family.xsd" ºÍ "attribute.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 attribute.xsd">

<person gender="female">
<firstname>Jane</firstname>
<lastname>Smith</lastname>
</person>

<person gender="male">
<firstname>David</firstname>
<lastname>Smith</lastname>
</person>

</persons>

ÉÏÃæÕâ¸ö XML ÎļþÊÇÓÐЧµÄ£¬ÕâÊÇÒòΪ schema "family.xsd" ÔÊÐíÎÒÃÇÏò "person" ÔªËØÌí¼ÓÊôÐÔ¡£

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

VUE