w3pop.com :: ÍøÂçѧԺ :: Schema (XSD) :: XSD <any> ÔªËØ
The <any> element enables us to extend the XML document with elements not specified by the schema!
<any>ÔªËØÄܹ»Ê¹ÎÒÃÇÔÚXMLÎĵµÖÐÌí¼Óδ±» schema ¶¨Òå¹ýµÄÐÂÔªËØ´Ó¶øÀ©³äXMLÎĵµ¡£
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"> |
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:element name="children"> </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" <person> <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