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

w3pop.com :: ÍøÂçѧԺ :: Schema (XSD) :: XSD ¼òµ¥ÔªËØ

»áÔ±µÇ½

ÕʺÅ

ÃÜÂë

»Ø´ð

¼ÇסÃÜÂë

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

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 ¼òµ¥ÔªËØ


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

XML Schemas define the elements of your XML files.
XML Schemas¶¨ÒåÁËXMLÎļþµÄÔªËØ¡£

A simple element is an XML element that contains only text. It cannot contain any other elements or attributes.
¼òµ¥ÔªËØÊÇÖ»°üº¬Îı¾µÄXMLÔªËØ¡£Ëü²»¿ÉÒÔÔÙ°üº¬ÆäËüÔªËØ»òÊôÐÔ¡£


What is a Simple Element?
ʲôÊǼòµ¥ÔªËØ£¿

A simple element is an XML element that can contain only text. It cannot contain any other elements or attributes.
¼òµ¥ÔªËØÊÇÖ»°üº¬Îı¾µÄXMLÔªËØ¡£Ëü²»¿ÉÒÔÔÙ°üº¬ÆäËüÔªËØ»òÊôÐÔ¡£

However, the "only text" restriction is quite misleading. The text can be of many different types. It can be one of the types included in the XML Schema definition (boolean, string, date, etc.), or it can be a custom type that you can define yourself.
È»¶ø£¬“Ö»°üº¬Îı¾”Õâ¸öÏÞ¶¨Ìõ¼þÊǷdz£ÈÝÒ×ÒýÆðÎó½âµÄ¡£Îı¾¿ÉÒÔ°üº¬¶àÖÖ²»Í¬ÀàÐÍ¡£Ëü¿ÉÒÔÊÇXML Schema¶¨ÒåÖеÄÎı¾ÀàÐÍÖ®Ò»£¨Âß¼­Öµ¡¢×Ö·û´®¡¢ÈÕÆÚ£¬µÈµÈ£©£¬Ò²¿ÉÒÔÊÇ×Ô¶¨ÒåÎı¾ÀàÐÍ¡£

You can also add restrictions (facets) to a data type in order to limit its content, or you can require the data to match a specific pattern.
Äã¿ÉÒÔͨ¹ýΪÊý¾ÝÀàÐÍÌí¼ÓÏÞ¶¨Ìõ¼þÀ´ÏÞÖÆËüµÄÄÚÈÝ£»»òÕߣ¬Äã¿ÉÒÔÒªÇóÊý¾ÝÓëÖ¸¶¨µÄÑùʽÏàÆ¥Åä¡£


Defining a Simple Element
¶¨ÒåÒ»¸ö¼òµ¥ÔªËØ

The syntax for defining a simple element is:
¶¨ÒåÒ»¸ö¼òµ¥ÔªËصÄÓï·¨ÈçÏ£º

<xs:element name="xxx" type="yyy"/>

where xxx is the name of the element and yyy is the data type of the element.
ÉÏÊö°¸ÀýÖУ¬ xxxÊÇÔªËØÃû³Æ£¬yyyÊÇÔªËØµÄÊý¾ÝÀàÐÍ¡£

XML Schema has a lot of built-in data types. The most common types are:
XML Schema±¾Éí°üº¬¶àÖÖÄÚÖõÄÊý¾ÝÀàÐÍ¡£×î³£¼ûµÄÀàÐÍÈçÏ£º

  • xs:string
    xs:×Ö·û
  • xs:decimal
    xs: СÊý
  • xs:integer
    xs:ÕûÊý
  • xs:boolean
    xs:Âß¼­Öµ
  • xs:date
    xs:ÈÕÆÚ
  • xs:time
    xs:ʱ¼ä

Example
°¸Àý

Here are some XML elements:
ÏÂÃæÁоÙÁËһЩXMLÔªËØ£º

<lastname>Refsnes</lastname>
<age>36</age>
<dateborn>1970-03-27</dateborn>

And here are the corresponding simple element definitions:
ÏÂÃæÁоÙÁËÏà¶Ô¼òµ¥µÄÔªËØ¶¨Ò壺

<xs:element name="lastname" type="xs:string"/>

<xs:element name="age" type="xs:integer"/>
<xs:element name="dateborn" type="xs:date"/>

 


Default and Fixed Values for Simple Elements
¼òµ¥ÔªËصÄĬÈÏÖµºÍ¹Ì¶¨Öµ

Simple elements may have a default value OR a fixed value specified.
¼òµ¥ÔªËØ¿ÉÒÔ°üº¬Ö¸¶¨µÄĬÈÏÖµ»ò¹Ì¶¨Öµ¡£

A default value is automatically assigned to the element when no other value is specified.
µ±Î´Ö¸¶¨ÆäËüֵʱ£¬ÊôÐÔ»á×Ô¶¯ÉèÖÃĬÈÏÖµ¡£

In the following example the default value is "red":
ÏÂÊö°¸ÀýµÄĬÈÏÖµÊÇ"red"£º

<xs:element name="color" type="xs:string" default="red"/>

A fixed value is also automatically assigned to the element, and you cannot specify another value.
¹Ì¶¨ÖµÊÇÒ²ÊÇϵͳ×Ô¶¯·ÖÅɸøÊôÐԵġ£²¢ÇÒ£¬Ò»µ©Ö¸¶¨Á˹̶¨Öµ£¬Äã¾Í²»ÄÜÖ¸¶¨ÆäËüÖµÁË¡£

In the following example the fixed value is "red":
ÏÂÊö°¸ÀýµÄ¹Ì¶¨ÖµÊÇ"red"£º

<xs:element name="color" type="xs:string" fixed="red"/>

ÆÀÂÛ (2) 1 All