w3pop.com :: ÍøÂçѧԺ :: Schema (XSD) :: XSD ¸´ºÏ¿ÕÔªËØ
An empty complex element cannot have contents, only attributes.
Ò»¸ö¿ÕµÄ¸´ºÏÔªËØ²»Äܰüº¬ÄÚÈÝ£¬Ö»Äܰüº¬ÊôÐÔ¡£
An empty XML element:
Ò»¸ö¿ÕµÄXMLÔªËØÈçÏ£º
<product prodid="1345" /> |
The "product" element above has no content at all. To define a type with no content, we must define a type that allows only elements in its content, but we do not actually declare any elements, like this:
ÉÏÊö"product"ÔªËØÍêÈ«²»°üº¬ÈκÎÄÚÈÝ¡£ÎªÁ˶¨Òå²»°üº¬ÄÚÈݵÄÀàÐÍ£¬ÎÒÃDZØÐ붨ÒåÒ»¸öÄÚÈÝÖÐÖ»ÔÊÐí³öÏÖÔªËØµÄÀàÐÍ¡£µ«ÊÇ£¬ÎÒÃDz»ÐèÒªÉùÃ÷ÈκÎÔªËØ£¬ÈçÏÂËùʾ£º
<xs:element name="product"> |
In the example above, we define a complex type with a complex content. The complexContent element signals that we intend to restrict or extend the content model of a complex type, and the restriction of integer declares one attribute but does not introduce any element content.
ÔÚÉÏÊö°¸ÀýÖУ¬ÎÒÃǶ¨ÒåÁËÒ»¸ö°üº¬¸´ºÏÄÚÈݵĸ´ºÏÀàÐÍ¡£¸´ºÏÄÚÈݵÄÔªËØÖ¸Ã÷ÁËÎÒÃÇÏëÒªÔ¼Êø»òÀ©³äµÄ¸´ºÏÀàÐ͵ÄÄÚÈÝģʽ£¬²¢¶ÔÕûÊýµÄÔ¼ÊøÌõ¼þÉùÃ÷ÁËÒ»¸öÊôÐÔ£¬µ«²»°üº¬¶ÔÔªËØÄÚÈݵĽéÉÜ¡£
However, it is possible to declare the "product" element more compactly, like this:
È»¶ø£¬ÎÒÃÇ»¹¿ÉÒÔ¸ü¼Ó¼ò½àµØÉùÃ÷"product"ÔªËØ£¬ÈçÏÂËùʾ£º
<xs:element name="product"> |
Or you can give the complexType element a name, and let the "product" element have a type attribute that refers to the name of the complexType (if you use this method, several elements can refer to the same complex type):
»òÕßÄã¿ÉÒÔ¸øcomplexTypeÔªËØÆð¸öÃû³Æ£¬²¢Ê¹"product"ÔªËØ°üº¬Ò»¸öÀàÐÍÊôÐÔ£¬²¢ÇÒ£¬ÀàÐÍÊôÐÔÒýÓõÄÊÇcomplexTypeµÄÃû³Æ£¨Èç¹ûÄãʹÓÃÕâ¸ö·½·¨£¬ÄÇô£¬¼¸¸öÔªËØ¾Í¿ÉÒÔÒýÓÃÏàͬµÄ¸´ºÏÀàÐÍ£©£º
<xs:element name="product" type="prodtype"/> <xs:complexType name="prodtype"> |
ÆÀÂÛ (0)
All