XML:可擴(kuò)展標(biāo)記語言
主要用于保存和傳輸數(shù)據(jù)
第一行:XML聲明,包括版本號與字符集
有且僅有一個(gè)根節(jié)點(diǎn)
標(biāo)簽書寫規(guī)則與html相同
標(biāo)簽名使用英文小寫字母,單詞之間用-分割,有意義
屬性:分組時(shí)常使用
處理特殊字符:實(shí)體引用,CData標(biāo)簽
實(shí)體引用:
CDATA標(biāo)簽:不應(yīng)由xml解析器進(jìn)行解析的文本數(shù)據(jù)
<![CDATA[
內(nèi)容
]]>
有序的子元素:xml多層嵌套的子元素中,順序應(yīng)一致
語義約束
DTD
定義hr的子節(jié)點(diǎn)employee
<!ELEMENT hr (employee)>
定義employee的子節(jié)點(diǎn)name,sex,age
<!ELEMENT employee (name,sex,age)>
name為文本類型
<!ELEMENT name (#PCDATA)>
子節(jié)點(diǎn)employee個(gè)數(shù)>=1
<!ELEMENT hr (employee+)>
子節(jié)點(diǎn)employee個(gè)數(shù)>=0
<!ELEMENT hr (employee*)>
子節(jié)點(diǎn)employee個(gè)數(shù)<=1
<!ELEMENT hr (employee?)>
編譯節(jié)點(diǎn)employee的no屬性
<!ATTLIST employee no CDATA "">
xml引用DTD文件
XML Schema
W3C標(biāo)準(zhǔn),.xsd文件
根節(jié)點(diǎn)
<element name="hr">
complexType標(biāo)簽含義是復(fù)雜節(jié)點(diǎn),包含子節(jié)點(diǎn)時(shí)必須使用這個(gè)標(biāo)簽
<sequence>
sequence里面的子節(jié)點(diǎn)必須按順序進(jìn)行嚴(yán)格書寫
<element name="age" >
<simpleType>//簡單類型約束
<restriction base="integer">//整數(shù)方面的限制
<minInclusive value="18"></minInclusive>//最小整數(shù)
<maxInclusive value="60"></maxInclusive>//最大整數(shù)
</restriction>
</simpleType>
</element>
</sequence>
<attribute name="no" type="string" use="required"></attribute>
use="required"意為:xml中每個(gè)子節(jié)點(diǎn)都有no屬性
</complexType>
</element>
xml綁定Scheme
在xml文件根節(jié)點(diǎn)中,如:
為根節(jié)點(diǎn)
<hr xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="hr.xsd">
hr.xsd為Scheme文件名
<element name="employee" minOccurs="1" maxOccurs="9999">
employee節(jié)點(diǎn)最少出現(xiàn)1次,最多出現(xiàn)9999次