xml语法笔记

 

全称:Extendsible Markup Language-可扩展的标记语言

 

作用:

              1,存储数据

              2,传输数据

xml – html区别

              xml表示数据的意义

              xml不控制数据的显示

              xml是自描述的

              xml规范严格

             

              html控制数据的显示样式

              html规范不严格

xml语法

              1,头标记,必须是文档的第一个字符

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

              2,顶层元素只能有一个

              3,标记必须有开始和结束

              4,空元素     <a></a> == <a />

              5,必须正确的嵌套(成对出现)

                     错:<a><b></a></b>

                     对:<a><b></b></a>

              6,属性必须用引号(单双都可以)括起来(标签后面跟属性)date="2011-11-20"

              7,XML实体 - Entity

                     转义:

                            &lt; - <

                            &gt; - >

                            &amp; - &

                            &quot; - "

                            &apos; - '

              8,PCDATA

                     Parsible Character Data(可解析的文本数据)

              9,转义标志:<![CDATA[内容]]>

                     Character Data

                     包含在此标记内的数据都作为普通字符处理

DTD - Document Type Defination(dtd)

              规定XML文档的格式规范

语法(ELEMENT、ATTLIST、ENTITY)

                     1,空元素EMPTY

                            <!ELEMENT abc EMPTY>

                            <abc></abc>

                            <abc />

                     2,包含任意内容ANY

                            <!ELEMENT abc ANY>

                     3,子元素序列,子元素必须出现且必须按顺序出现

                            <!ELEMENT abc (def,ghi,jkl)>

                            <abc>

                                   <def></def>

                                   <ghi></ghi>

                                   <jkl></jkl>

                            </abc>

                     4,出现次数 ?:0次或1次 +:1次或多次 *:0次或多次

                            <!ELEMENT abc (def?,ghi+,jkl*)>

                     5,或| 二选一(必须出现一个)

                            <!ELEMENT abc (def,(ghi|jkl))>

                            <abc>

                                   <def></def>

                                   <ghi></ghi>

                            </abc>

                            <abc>

                                   <def></def>

                                   <jkl></jkl>

                            </abc>

                     6,属性默认值CDATA

                            <!ATTLIST dept id CDATA "0" >

                                   默认值为0

                     7,可选属性#IMPLIED

                            <!ATTLIST dept id CDATA #IMPLIED >

                     8,必选属性#REQUIRED

                            <!ATTLIST dept id CDATA #REQUIRED >

                     9,属性具有固定值#FIXED

                            <!ATTLIST dept company CDATA #FIXED "tarena" >

                     10,属性具有几个固定可选值(a|b|c)

                            <!ATTLIST dept company CDATA (tarena|Microsoft|Oracle) "tarena">//"tarena"默认值

                     11,实体(转义)

                            <!ENTITY copyright "copyright(c) tarena.com.cn 2010">

                            &copyright

 

 

 

你可能感兴趣的:(xml语法笔记)