w3pop.com :: ÍøÂçѧԺ :: Schema (XSD) :: ΪºÎʹÓà XML Schemas?
ΪºÎʹÓà XML Schemas?
::
XML Schemas are much more powerful than DTDs.
XML Schema±ÈDTD¹¦Äܸü¼ÓÇ¿´ó¡£
One of the greatest strength of XML Schemas is the support for data types.
XML SchemaµÄ×îÇ¿´óµÄ¹¦ÄÜÖ®Ò»¾ÍÊÇËüÖ§³ÖÊý¾ÝÀàÐÍ¡£
With support for data types:
Ö§³ÖÊý¾ÝÀàÐ͵ĺô¦£º
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µÄºÃ´¦ÊÇ£º
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, because they are written in XML.
ÒòΪXML SchemaÎļþÊÇÓÉXML±àдµÄ£¬ËùÒÔËüÃÇÊÇ¿ÉÀ©Õ¹µÄ¡£
With an extensible Schema definition you can:
SchemaµÄÀ©Õ¹ÐÔ¿ÉÒÔ°üº¬ÏÂÊö¶¨Ò壺
A well-formed XML document is a document that conforms to the XML syntax rules, like:
¹æ·¶µÄXMLÎĵµÊÇ·ûºÏXMLÓï·¨¹æÔòµÄÎĵµ£¬¾ßÌåÈçÏ£º
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