XML Syntax

XML Syntax Intrucuction
 
 
  • CDATA

    <![CDATA[

                                             if ( a > b ) {
                                                         printf("in if : a > b\n");
                                              } else {
                                                          printf("in else : a <= b\n");
                                               }

               ]]>

  • Comment

                                    <!-- Single Comment Line -->

                                     <!--

                                              Multiple Coment Part :

                                                    line#1

                                                    line#2

                                                    line#3

                                     -->

  • DOCTYPE

                                   Single Layer

                                <!DOCTYPE note [

                                                      <!ENTITY CompanyName 'Liquid Technologies Ltd'>

                                     ]>

 

                                      Multiple Layers

                                      <!DOCTYPE note [

 

                                                             <!ELEMENT body1 (#PCDATA)>
                                                                        [ innerContent1
                                                                           <!ELEMENT body2 (#PCDATA)>
                                                                               [ innerContent2
                                                                                  <!ELEMENT body3 (#PCDATA)>
                                                                               ]
                                                                         ]

                                          ]>

 

 

  • Declaration

                                   <?xml version="1.0" encoding="UTF-8"?>

                                   <?XML version="1.0" encoding="UTF-8"?>

                                   <?xMl version="1.0" encoding="UTF-8"?>

 

  • Process Instruction (PI)

                                               <?stylesheet type="text/xsl" href="/Content/Glossary/main.xsl"?>

                                               <?HeaderName key1="value1" key2="value2" .... ?> // Notes : HeaderName is a must


                                    <Invalid> e.g.  !!![ERROR]!!!!
                                                    <? key1="value1" key2="value2" .... ?> // Without   HeaderName   is not allowed 

 

 

Text For Character References

&# Decimal-Number ;            // ';'   is a must
&#x Hex-Number  ;              // ';'   is a must, 注意,必需是小写的 x,     不能是 大写的 X
 
注意 :
                这些 Code 通常是以 Unicode (UTF-32 bits) 的形式被 XML 解析器所解析的
e.g.
            <aaa>&#x6211;&#x4EEC;</aaa>                  //    会显示出  <aaa></aaa> 的字样
 
 
 e.g.

<textForCharacterReferences>&#97;&#x61;</textForCharacterReferences>
<!-- These lines are all comment
       The above text is "aa" , because ‘a’ = 97(10) =0x61(16)
        &# + digit number + ;                                                             // decimal mode (10)
       &#x + hex number(either A-F or a~f is OK ) + ;                      // hex mode (16)
-->


 

 
 
在 XML 中,有 5 个预定义的实体引用:
 
&lt;  <  小于
&gt;  > 大于
&amp; & 位 与
&apos;  ' 单引号
&quot; " 双引号
 
 
 
 
 
 
 
 
 

XML 的详细教程文档
                     https://www.cnblogs.com/cb0327/p/4967782.html

 

空内容 |  混合 子标签 + 文本 | 单标签  | 
  • 空内容 

                           <aaa></aaa>                         // 内容

                                            <aaa>Hello</aaa>               //  内容

 

  • 混合 子标签 + 文本

                                             <root>

                                                     Hello  World  Line #1

                                                      bbb<Child>Hello</Child>aaa

                                                      Hello World  Line #2

                                             </root>

 

  • 单标签

 

        Syntax :
                         <tagName /> 
                           or
                      <tagName/>
 
e.g. 

<?xml version="1.0" encoding="utf-8"?>
<plist version="1.0">
    <a>content</a>
    <b />
    <c/>
</plist>


 

混合 子标签 + 文本

 

 

 

Namespace of XML:

h:



<table> <name>African Coffee Table</name> <width>80</width> <length>120</length> </table> <h:table> <h:tr> <h:td>Apples</h:td> <h:td>Bananas</h:td> </h:tr> </h:table>



 

posted @ 2024-07-25 21:17  EdisoNewton  阅读(13)  评论(0)    收藏  举报