XML Schema nillable=¡±true¡± vs minOccurs=¡±0¡å
³ö´¦£ºhttp://www.dimuthu.org/blog/2008/08/18/xml-schema-nillabletrue-vs-minoccurs0/
¡¾Ç°ÑÔ¡¿Ò»¸öÔÂÇ°Ñо¿¹ýnillable="true"ºÍ vs minOccurs="0"µÄÇø·Ö£¬Ã»ÓÐÏëµ½°¡£¬½ñÌì¾Í¼Ç²»µÃÁË£¬¿´À´ÕæÊǺüÇÐÔ²»ÈçÀñÊÍ·°¡£¬¿öÇÒÎÒ»¹Ã´µÄºÃ¼ÇÐÔ¡£¡£¡£¡£
¡¾×ܽ᡿ӢÎÄÒ»ÑÛ¿´²»³ö½áÂÛ£¬ËµµãººÓïÖ±½ÓЩ£¬±ð˵ÎÒÍÁ¹þ~
nillable="true"£º¸ÃÔªËصÄÖµ¿ÉÒÔΪ¿Õ£¬µ«ÊǸÃÔªËز»ÄÜÊ¡ÂÔ£¬Ò²¾ÍÊÇ˵£¬Ö»ÄÜ£º
<minzero xsi:nil="true"><minzero>
¶ø²»ÄÜÖ±½Ó½«minzeroÕâ¸öÔªËØÈ¥µô
£¨×¢Ò⣺xsi:nil="true"»òÕßxsi:nil="1"Ó¦¸Ã¾ÍÊDZíʾÕâ¸öÔªËØΪ¿Õ£©
minOccurs="0"£º¸ÃÔªËØ¿ÉÒÔÖ±½Ó±»Ê¡ÂÔµô£¬µ«ÊDz»ÄÜÈøÃÔªËصÄֵΪ¿Õ£¬Ò²¾ÍÊÇ˵£¬²»ÄÜ£º
<minzero xsi:nil="true"><minzero>
In a WSDL, XML Schema is the section where it define the message format for each operations, which eventually become the real API that users are interested. And it is the most tricky part of the WSDL. Nowadays there are many tools that you can design and use WSDLs without any needs in knowing the meaning of a single line of the WSDL. But there are situations that you may find it is better you have some knowledge in XML Schema section and in WSDL overall.
For this post I m taking a simple example of use of nillable=”true” and minOccurs=”0″. Take the following example.
<xs:element name="myelements">
<xs:complexType>
<xs:sequence>
<xs:element name="nonboth" type="xs:string"/>
<xs:element minOccurs="0" name="minzero" type="xs:int"/>
<xs:element name="nilint" nillable="true" type="xs:int"/>
<xs:element name="nilstring" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" name="minzeronil" nillable="true" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
Just ignore the meaning of what nillable and minOccurs attributes for now. You can safely say the following XML is valid for the above Schema.
<myelements>
<nonboth>i can't be either nil nor skipped<nonboth>
Ïà¹ØÎĵµ£º
Óŵ㣺ÓÉÓÚxmlÊÇ¿ÉÀ©Õ¹µÄ£¬ËùÒÔxml¿ÉÒÔÃèÊöÀ´×Ô¶àÖÖÓ¦ÓóÌÐòµÄÊý¾Ý¡£
ͨ¹ýÁ£¶È¸üÐÂÀ´Ìá¸ßÐÔÄÜ¡£XML ÔÊÐíÁ£¶È¸üС£¿ª·¢ÈËÔ±²»±ØÔÚÿ´Î¸Ä¶¯Ê±¶¼·¢ËÍÕû¸ö½á¹¹»¯Êý¾Ý¼¯¡£ÓÐÁËÁ£¶È¸üкó£¬Ö»ÓиıäµÄÔªËزŴӷþÎñÆ÷·¢Ë͵½¿Í»§»ú¡£ ......
½ñÌ칤×÷ÉÏÅöµ½Ò»¸öÎÊÌâ ÓÉÓÚÎÒÃǵÄÏîÄ¿Êý¾ÝÌ«ÉÙ ËùÒÔÐèÒª´Óweb searchÄDZ߽èµ÷Êý¾Ý£¬ËûÃÇÖ»¸øÎÒÃÇÌṩÁËÒ»¸öxmlµÄ½Ó¿Ú¡£Òò´Ë£¬ÎÒÃÇÐèÒª°ÑxmlµÄÊý¾Ýת»¯³Éhtml³ÊÏÖ¸ø´ó¼Ò¡£ÓÉÓÚÏîÄ¿ÊÇ»ùÓÚphpµÄ£¬ËùÒÔ¾ÍÞðÆúÁËÓÃjsÀ´¶ÁÈ¡xmlÑ¡ÔñÁ˼ÌÐøʹÓÃphp¡£²»¹ý£¬ÎÒÒÔÇ°´ÓÀ´Ã»ÓÐ×ö¹ý´ËÀàµÄ³¢ÊÔ ËùÒÔÕÒÁ˺ܶàÍøÉÏ×ÊÁÏͬʱ²ÎÕÕÁËphpµÄ¹¤× ......
Êý¾Ý¿âÓ¦ÓÃϵͳ°üÀ¨Êý¾Ý¿â£¬Êý¾Ý¿â¹ÜÀíϵͳ£¬Êý¾Ý¿âÓ¦ÓÃÈý´ó²¿·Ö¡£
ÊÀ½çÉÏ´æÔÚÐí¶àÍêÈ«²»Í¬µÄ¿Í»§Æ½Ì¨£¬ÔÚ²»Í¬Æ½Ì¨¼ä½»»»Êý¾Ý£¬ÐèÒª±£Ö¤Êý¾ÝµÄÍêÕûºÍ·þÎñµÄ¸ßЧ£¬Êý¾Ý¸ñʽµÄת»»ÎÊÌâÍùÍù³ÉΪÖÆÔ¼Web ServiceµÄÆ¿¾±£¬²ÉÓÃXML×÷ΪÊý¾Ý½»»»µÄ±ê×¼£¬¿ÉÒÔʹ¸÷¸öÒ칹ƽ̨ºÍ¸÷ÖÖ¸ñʽµÄÊý¾Ý½øÐÐÊý¾Ý½»»»³ÉΪ¿ÉÄÜ¡£
......
CollectionÖ÷ÒªÊÇÖ¸ÏñArray, ArrayList, List, Dictionary, HashTableÕâЩÊý¾ÝÀàÐÍ£¬´ó¼ÒƽʱÓõĺܶࡣÈç¹ûÒ»¸öÀàÖÐÓÐÒ»¸öCollectionÀàÐ͵ijÉÔ±£¬ÔÚ¶ÔÕâ¸öÀà½øÐÐXMLÐòÁл¯µÄʱºò£¬Ó¦¸ÃÈçºÎ´¦Àí£¿Ó¦¸Ã˵ÔÚ.netµ±ÖÐÕâÊDZȽϼòµ¥µÄ£¬Ö»Òª½¨Á¢Ò»¸öXmlSerializerÀà¾Í¿ÉÒÔ°ïÄã×Ô¶¯¸ã¶¨£¬²»¹ýÓеÄʱºòÄã¿ÉÄÜÐèÒª¶Ô×Ô¶¯µÄÐòÁл¯¹ý³ ......
½âÎö£º
CMarkup xml;
CString strChanText, strChanType;
xml.Load("MyXml.xml");
xml.ResetMainPos();
if (!Chan.FindElem("TreeOrg"))
{
return;
}
if (xml.IntoElem())
{
xml.FindEle ......