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

w3pop.com :: ÍøÂçѧԺ :: Schema (XSD) :: ΪºÎʹÓà XML Schemas?

»áÔ±µÇ½

ÕʺÅ

ÃÜÂë

»Ø´ð

¼ÇסÃÜÂë

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

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 СÊýÊý¾ÝÀàÐÍ

ΪºÎʹÓà XML Schemas?


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

XML Schemas are much more powerful than DTDs.
XML Schema±ÈDTD¹¦Äܸü¼ÓÇ¿´ó¡£


XML Schemas Support Data Types
XML SchemaÖ§³ÖÊý¾ÝÀàÐÍ

One of the greatest strength of XML Schemas is the support for data types.
XML SchemaµÄ×îÇ¿´óµÄ¹¦ÄÜÖ®Ò»¾ÍÊÇËüÖ§³ÖÊý¾ÝÀàÐÍ¡£

With support for data types:
Ö§³ÖÊý¾ÝÀàÐ͵ĺô¦£º

  • It is easier to describe allowable document content
    ¸üÒ×ÓÚÃèÊöÔÊÐíʹÓõÄÎĵµÄÚÈÝ
  • It is easier to validate the correctness of data
    ¸üÒ×ÓÚ¼ìÑéÊý¾ÝµÄÓÐЧÐÔ
  • It is easier to work with data from a database
    ¸üÒ×ÓÚÓëÊý¾Ý¿âÖеÄÊý¾ÝÒ»ÆðЭͬ¹¤×÷
  • It is easier to define data facets (restrictions on data)
    ¸üÒ×ÓÚ¶¨ÒåÊý¾ÝÃæ£¨¹ØÓÚÊý¾ÝµÄÏÞÖÆ£©
  • It is easier to define data patterns (data formats)
    ¸üÒ×ÓÚ¶¨ÒåÊý¾ÝÑùʽ£¨Êý¾Ý¸ñʽ£©
  • It is easier to convert data between different data types
    ¸üÒ×ÓÚ½«Êý¾ÝÔÚ²»Í¬µÄÊý¾ÝÀàÐÍÖ®¼ä½øÐÐת»»

XML Schemas use XML Syntax
XML SchemaʹÓÃXMLÓï·¨

Another great strength about XML Schemas is that they are written in XML.
XML SchemaÁíÒ»¸öºÃ´¦¾ÍÊÇËûÃÇÊÇÓÃXML±àд³ÉµÄ¡£

Some benefits of that XML Schemas are written in XML:
ÓÃXML±àдXML SchemaµÄºÃ´¦ÊÇ£º

  • You don't have to learn a new language
    ¿ÉÒÔ²»ÐèÒªÔÙѧϰһÖÖȫеÄÓïÑÔ
  • You can use your XML editor to edit your Schema files
    ¿ÉÒÔʹÓÃXML±à¼­Æ÷À´±à¼­SchemaÎļþ
  • You can use your XML parser to parse your Schema files
    ¿ÉÒÔʹÓÃXML½âÎöÆ÷½âÎöSchemaÎļþ
  • You can manipulate your Schema with the XML DOM
    ¿ÉÒÔʹÓÃXML DOM ´¦ÀíSchema
  • You can transform your Schema with XSLT
    ¿ÉÒÔʹÓÃXSLTת»»Schema

XML Schemas Secure Data Communication
XML Schema°²È«Êý¾ÝͨѶ

When sending data from a sender to a receiver, it is essential that both parts have the same "expectations" about the content.
µ±Êý¾ÝÓÉ·¢ËÍÕß´«µÝ¸ø½ÓÊÜÕßʱ£¬Ë«·½¶Ô“Êý¾ÝÄÚÈÝÀí½âµÄÒ»ÖÂÐÔ”¾ÍÏԵ÷dz£ÖØÒª¡£

With XML Schemas, the sender can describe the data in a way that the receiver will understand.
ÔÚXML SchemaÀ·¢ËÍÕß¿ÉÒÔÓýÓÊÜÕßÄܹ»Àí½âµÄ·½Ê½ÃèÊöÊý¾Ý¡£

A date like: "03-11-2004" will, in some countries, be interpreted as 3.November and in other countries as 11.March.
ÏñÕâÑù¸ñʽµÄÈÕÆÚ£º"03-11-2004"£¬Ä³Ð©¹ú¼Ò»á½âÊͳÉ11ÔÂ3ÈÕ£¬¶øÄ³Ð©¹ú¼Ò¿ÉÄÜ»á½âÊͳÉ3ÔÂ11ÈÕ

However, an XML element with a data type like this:
<date type="date">2004-03-11</date>
ensures a mutual understanding of the content, because the XML data type "date" requires the format "YYYY-MM-DD".
È»¶ø£¬Í¨¹ýÒ»¸ö°üº¬±ê×¼Êý¾ÝÀàÐ͵ÄXMLÔªËØ¾Í¿ÉÒÔ½â¾öÕâ¸öÎÊÌ⣬¾ßÌåÈçÏ£º<date type="date">2004-03-11</date>£¬ÕâÑù¾ÍÈ·±£ÁËË«·½¶¼Äܹ»Àí½âÆäÖеÄÄÚÈÝ¡£ÒòΪXMLÊý¾ÝÀàÐ͵Ä"date"ÒªÇ󽫸ñʽ¹æ¶¨Îª"YYYY-MM-DD"¡£


XML Schemas are Extensible
XML SchemaÊÇ¿ÉÀ©Õ¹µÄ

XML Schemas are extensible, because they are written in XML.
ÒòΪXML SchemaÎļþÊÇÓÉXML±àдµÄ£¬ËùÒÔËüÃÇÊÇ¿ÉÀ©Õ¹µÄ¡£

With an extensible Schema definition you can:
SchemaµÄÀ©Õ¹ÐÔ¿ÉÒÔ°üº¬ÏÂÊö¶¨Ò壺

  • Reuse your Schema in other Schemas
    ÔÚÆäËüµÄSchemaÎļþÖÐÔÙ´ÎÔÙ´ÎʹÓÃÄãµÄSchema
  • Create your own data types derived from the standard types
    ´Ó±ê×¼µÄÊý¾ÝÀàÐÍÖÐÅÉÉú³öÄã×Ô¼ºµÄÊý¾ÝÀàÐÍ
  • Reference multiple schemas in the same document
    ÔÚÏàͬµÄÎĵµÖвο¼¶àÖÖSchema

Well-Formed is not Enough
¹âÓГ¹æ·¶”ÈÔÈ»ÊDz»¹»µÄ

A well-formed XML document is a document that conforms to the XML syntax rules, like:
¹æ·¶µÄXMLÎĵµÊÇ·ûºÏXMLÓï·¨¹æÔòµÄÎĵµ£¬¾ßÌåÈçÏ£º

  • it must begin with the XML declaration
    ¿ªÍ·±ØÐë°üº¬XMLÉùÃ÷
  • it must have one unique root element
    ±ØÐëÓÐÒ»¸ö¶ÀÁ¢µÄ¸ùÄ¿Â¼ÔªËØ
  • start-tags must have matching end-tags
    Æðʼ±êÇ©±ØÐëºÍ½áÊø±êǩƥÅä
  • elements are case sensitive
    ÔªËØÇø·Ö×Öĸ´óСд
  • all elements must be closed
    ËùÓÐÔªËØ±ØÐë°üº¬½áÊø±êÇ©
  • all elements must be properly nested
    ËùÓÐÔªËØ±ØÐë±»ºÏÀíǶÌ×
  • all attribute values must be quoted
    ËùÓÐÊôÐÔÖµ±ØÐëдÔÚÒýºÅÄÚ
  • entities must be used for special characters
    ʵÌ屨Ðë±»ÓÃÓÚÌØ¶¨×Ö·û

Even if documents are well-formed they can still contain errors, and those errors can have serious consequences.
¼´Ê¹ÎĵµÊǹ淶µÄ£¬ËüÃÇÒ²¿ÉÄܰüº¬´íÎó£»²¢ÇÒ£¬ÕâЩ´íÎó¿ÉÄÜ»áÒýÆðÑÏÖØµÄºó¹û¡£

Think of the following situation: you order 5 gross of laser printers, instead of 5 laser printers. With XML Schemas, most of these errors can be caught by your validating software.
ÊÔ×ÅÏëÏëÏÂÊöÇé¿ö£ºÄãÔ¤¶¨ÁË5ÂÞ£¨1ÂÞ=12´ò=144̨£©¼¤¹â´òÓ¡»ú£¬¶ø²»ÊÇ5̨´òÓ¡»ú¡£ÔÚXML SchemaÎļþÀ´ó¶àÊýÀàËÆÕâÑùµÄ´íÎó»áÓɼìÑéÈí¼þ²úÉú¡£

ÆÀÂÛ (0) All