ÍøÂçѧԺ w3popÉçÇø ÍøÂç×ÊÔ´ ITÐÂÎÅ

w3pop.com :: ÍøÂçѧԺ :: Schema (XSD) :: XSD <anyAttribute> ÔªËØ

»áÔ±µÇ½

ÕʺÅ

ÃÜÂë

»Ø´ð

¼ÇסÃÜÂë

Íü¼ÇÃÜÂë? ×¢²á

Schema (XSD)
Schema (XSD) ½éÉ..
ΪºÎʹÓà XML Sch..
ÈçºÎ¶¨ÖÆ XSD
XSD - <schema..
XSD ¼òµ¥ÔªËØ
XSD ÊôÐÔ
XSD Ô¼ÊøÃæ
XSD ¸´ºÏÔªËØ
XSD ¸´ºÏ¿ÕÔªËØ
XSD ¸´ºÏ´¿ÔªËØ
XSD ¸´ºÏ´¿Îı¾
XSD »ìºÏÄÚÈݵĸ´..
XSD ָʾÆ÷¸´ºÏÀà..
XSD <any> ..
XSD <anyAttri..
XSD ÔªËØÌæ´ú
XSD ʵÀý
XSD ×Ö·û´®Êý¾ÝÀà..
XSD ÈÕÆÚÊý¾ÝÀàÐÍ
XSD СÊýÊý¾ÝÀàÐÍ

XSD <anyAttribute> ÔªËØ


×÷Õß:w3pop.com ·­Òë/ÕûÀí:w3pop.com ·¢²¼:2007-04-29 ÐÞ¸Ä:2007-08-28 ä¯ÀÀ:4175 :: ::

The <anyAttribute> element enables us to extend the XML document with attributes not specified by the schema!
<anyAttribute> ÔªËØÄܹ»Ê¹ÎÒÃÇÔÚXMLÎĵµÖÐÌí¼Óδ±»schemaÖ¸¶¨¹ýµÄÊôÐÔ£¡


The <anyAttribute> Element
<anyAttribute>ÔªËØ

The <anyAttribute> element enables us to extend the XML document with attributes not specified by the schema.
<anyAttribute> ÔªËØÄܹ»Ê¹ÎÒÃÇÔÚXMLÎĵµÖÐÌí¼Óδ±»schemaÖ¸¶¨¹ýµÄÊôÐÔ¡£

The following example is a fragment from an XML schema called "family.xsd". It shows a declaration for the "person" element. By using the <anyAttribute> element we can add any number of attributes to the "person" element:
ÏÂÃæÁоÙÁËÃûΪ "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>

Now we want to extend the "person" element with a "gender" attribute. In this case we can do so, even if the author of the schema above never declared any "gender" attribute.
ÏÖÔÚ£¬ÎÒÃÇÏ£ÍûÔÚ"person"ÔªËØÖÐÌí¼Ó"gender"ÊôÐÔ¡£ËäÈ»ÕâÆªschemaÎļþµÄ×÷Õß²¢Î´ÉùÃ÷"gender"ÊôÐÔ£¬µ«ÊÇ£¬ÎÒÃÇÒ»Ñù¿ÉÒÔ×öµ½¡£

Look at this schema file, called "attribute.xsd":
Çë¿´ÏÂÃæÕâ·ÝÃûΪ"attribute.xsd"µÄschemaÎļþ£º

<?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"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:schema>

The XML file below (called "Myfamily.xml"), uses components from two different schemas; "family.xsd" and "attribute.xsd":
ÏÂÃæµÄÕâ·ÝÃûΪ "Myfamily.xml" µÄ 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.w3schools.com attribute.xsd">
<person gender="female">
<firstname>Hege</firstname>
<lastname>Refsnes</lastname>

</person>
<person gender="male">
<firstname>Stale</firstname>
<lastname>Refsnes</lastname>
</person>
</persons>

The XML file above is valid because the schema "family.xsd" allows us to add an attribute to the "person" element.
ÉÏÊöXMLÎļþÊÇÓÐЧµÄ¡£ÒòΪÃûΪ"family.xsd" µÄ schema ÎļþÔÊÐíÎÒÃÇÔÚ"person"ÔªËØÀïÌí¼ÓÊôÐÔ¡£

The <any> and <anyAttribute> elements are used to make EXTENSIBLE documents! They allow documents to contain additional elements that are not declared in the main XML schema.
<any> ºÍ <anyAttribute> ÔªËØÊÇÓÃÓÚÀ©Õ¹ÎĵµµÄ£¡ËüÃÇÔÊÐíÎĵµÖаüº¬Î´ÔÚÖ÷Ìå XML schema ÖÐÉùÃ÷µÄÆäËüÐÂÔªËØ¡£

ÆÀÂÛ (0) All