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

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

»áÔ±µÇ½

ÕʺÅ

ÃÜÂë

»Ø´ð

¼ÇסÃÜÂë

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

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 <any> ÔªËØ


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

The <any> element enables us to extend the XML document with elements not specified by the schema!
<any>ÔªËØÄܹ»Ê¹ÎÒÃÇÔÚXMLÎĵµÖÐÌí¼Óδ±» schema ¶¨Òå¹ýµÄÐÂÔªËØ´Ó¶øÀ©³äXMLÎĵµ¡£


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

The <any> element enables us to extend the XML document with elements not specified by the schema.
<any>ÔªËØÄܹ»Ê¹ÎÒÃÇÔÚXMLÎĵµÖÐÌí¼Óδ±» schema ¶¨Òå¹ýµÄÐÂÔªËØ´Ó¶øÀ©³äXMLÎĵµ¡£

The following example is a fragment from an XML schema called "family.xsd". It shows a declaration for the "person" element. By using the <any> element we can extend (after <lastname>) the content of "person" with any element:
ÏÂÊö°¸ÀýÊÇÃûΪ"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>

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

Look at this schema file, called "children.xsd":
Çë¿´ÏÂÃæÕâ·ÝÃûΪ"children.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:element name="children">
<xs:complexType>

<xs:sequence>
<xs:element name="childname" type="xs:string"
maxOccurs="unbounded"/>
</xs:sequence>

</xs:complexType>
</xs:element>
</xs:schema>

The XML file below (called "Myfamily.xml"), uses components from two different schemas; "family.xsd" and "children.xsd":
ÏÂÃæÕâ·ÝÃûΪ"Myfamily.xml"µÄXMLÎļþ£¬Ê¹ÓÃÁËÀ´×ÔÓÚ "family.xsd" ºÍ "children.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 children.xsd">
<person>
<firstname>Hege</firstname>
<lastname>Refsnes</lastname>

<children>
<childname>Cecilie</childname>
</children>
</person>
<person>
<firstname>Stale</firstname>

<lastname>Refsnes</lastname>
</person>
</persons>

The XML file above is valid because the schema "family.xsd" allows us to extend the "person" element with an optional element after the "lastname" element.
ÉÏÊöXMLÎļþÊÇÓÐЧµÄ£¬ÒòΪÃûΪ"family.xsd"µÄschemaÎļþÔÊÐíÎÒÃÇÔÚ"person"ÔªËØÖеÄ"lastname"ÔªËØºóÃæÀ©³äÒ»¸öÈÎÒâÔªËØ¡£

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