首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

xml dtd 学习总结

2012-12-27 
xml dtd 学习小结目录:xml+dtd 定义实例 By shawl.qiu1 简单的 xml+dtd1.1 xml1.2 css2 简单的 xml+dtd 13

xml dtd 学习小结

目录:
xml+dtd 定义实例 By shawl.qiu
1 简单的 xml+dtd
1.1 xml
1.2 css
2 简单的 xml+dtd 1
3 xml+dtd-定义属性
3.1 定义默认属性
3.2 NMTOKEN && NMTOKENS
3.3 ID?
3.4 IDREF
3.5 ENTITY && ENTITIES
3.5.0 公式
3.5.0.1 内部带参数 ENTITY?
3.5.0.1.1 外部带参数 ENTITY

3.5.1 文本 ENTITY
3.5.2 自定义字符
3.5.3 引用外部文件
3.5.3.1 主文件
3.5.3.2 x13Header.xml
3.5.3.3 x13Footer.xml
3.5.4 带参数 ENTITY
3.5.4.1 内部 带参数 ENTITY
3.5.4.2 外部 带参数 ENTITY
3.5.4.2.1 x15.xml
3.5.4.2.2 x15.dtd
3.6 NOTATION
4 xml+dtd-CDATA
5 xml+dtd-EMPTY-ANY
6 多种方法定义 dtd
7 dtd 子定义
8 dtd 类型混用
9 外部 dtd
9.1 私有 dtd
9.1.1 简单私有 dtd
9.1.1.1 x6.xml
9.1.1.2 x6.dtd
10 xml+dtd-xmlns
10.1 xml+dtd - xmlns 子名称空间
11 INCLUDE && IGNORE
11.0 公式
1.11.1 dtd 定义
shawl.qiu
2006-12-10
http://blog.csdn.net/btbtd
内容:
xml+dtd 定义实例 By shawl.qiu
1 简单的 xml+dtd
1.1 xml
<?xmlversion="1.0"?encoding="UTF-8"?>
<?xml-stylesheethref="x2.css"?type="text/css"?>
<!DOCTYPEbody?[
<!ELEMENTbody(blocks)*>
<!ELEMENTblocks(title,text)>
<!ELEMENTtitle(#PCDATA)>
<!ELEMENTtext(#PCDATA)>
]>
<body>
<blocks>
<title>title 1</title>
<text>text 1</text>
</blocks>
<blocks>
<title>title 2</title>
<text>text 2</text>
</blocks>
<blocks>
<title>title 2</title>
<text>text 2</text>
</blocks>
</body>
1.2 css
/* shawl.qiu CSS Document :?shawl.qiu@gmail.com?*/
block{background-color:gray;}
title, text{display:block;}
title{color:red;}
text{color:blue;}
text:first-letter{padding:0px 0px 0px 20px;}
2 简单的 xml+dtd 1
<?xmlversion="1.0"?encoding="UTF-8"?>
<!DOCTYPEbody?[
<!ELEMENTbody(blocks)*>
<!ELEMENTblocks(title,content)?>
<!ELEMENTtitle(#PCDATA)>
<!ELEMENTcontent(summary,text)*>
<!ELEMENTsummary(#PCDATA)>
<!ELEMENTtext(#PCDATA)>
]>
<body>
<blocks>
<title>this title 1</title>
<content>
<summary>summary text</summary>
<text>the text</text>
</content>
</blocks>
</body>
3 xml+dtd-定义属性
<?xmlversion="1.0"?encoding="UTF-8"?>
<!DOCTYPEdocument?[
<!ELEMENTdocument(section)*>
<!ELEMENTsection(title,content)>
<!ELEMENTtitle(#PCDATA)>
<!ELEMENTcontent(summary,text)>
<!ELEMENTsummary(#PCDATA)>
<!ELEMENTtext(#PCDATA)>
<!ATTLISTsection id CDATA?#REQUIRED>
<!ATTLISTtitle id CDATA?#IMPLIED>
<!ATTLISTtitle xml:lang CDATA?#IMPLIED>
]>
<document>
<sectionid="ok">
<titleid="hasId"?xml:lang="zh-CN" >这是一个测试</title>
<content>
<summary></summary>
<text></text>
</content>
</section>
<sectionid="no">
<titlexml:lang="en-US">这是一个测试</title>
<content>
<summary></summary>
<text></text>
</content>
</section>
</document>
3.1 定义默认属性
<?xmlversion="1.0"?encoding="UTF-8"?>
<!DOCTYPEdocument?[
<!ELEMENTdocument(block)+>
<!ELEMENTblock(id,title,contents,comment?,display)>
<!ELEMENTid?EMPTY>
<!ATTLISTid
idArticle CDATA "empty"
idSpid CDATA "empty"
idSbid CDATA "empty"
>
<!ELEMENTtitle(#PCDATA)>
<!ELEMENTcontents(summary,text)>
<!ELEMENTsummary(#PCDATA)>
<!ELEMENTtext(#PCDATA)>
<!ELEMENTcomment(idMsg,nick,msg)>
<!ATTLISTcomment
switch CDATA #FIXED "on"
>
<!ELEMENTidMsg(#PCDATA)>
<!ELEMENTnick(#PCDATA)>
<!ELEMENTmsg(#PCDATA)>
<!ELEMENTdisplay?EMPTY>
<!ATTLISTdisplay?
show (yes|no) 'yes'?
>
<!--枚举属性值-->
]>
<document>
<block>
<id/>
<title/>
<contents>
<summary/>
<text/>
</contents>
<comment>
<idMsg/>
<nick/>
<msg/>
</comment>
<display?/>
</block>
<block>
<ididArticle="1"?idSpid="1"?idSbid="1"/>
<title/>
<contents>
<summary/>
<text/>
</contents>
<comment>
<idMsg/>
<nick/>
<msg/>
</comment>
<displayshow="no" />
</block>
</document>
3.2 NMTOKEN && NMTOKENS
<?xmlversion="1.0"?encoding="UTF-8"?>
<!DOCTYPEdocument?[
<!ELEMENTdocument(block)+>
<!ELEMENTblock(title,content)>
<!ELEMENTtitle(#PCDATA)>
<!ATTLISTtitle?
desc NMTOKEN #REQUIRED
>
<!ELEMENTcontent(summary,text)>
<!ATTLISTcontent
about NMTOKENS #IMPLIED
>
<!ELEMENTsummary(#PCDATA)>
<!ELEMENTtext(#PCDATA)>
]>
<document>
<block>
<titledesc="strictValue">title this</title>
<contentabout="could have whitespace">
<summary>the summary</summary>
<text>that's text</text>
</content>
</block>
</document>
3.3 ID?
<?xmlversion="1.0"?encoding="UTF-8"?>
<!DOCTYPEdocument?[
<!ELEMENTdocument(block)+>
<!ELEMENTblock(id,title,content)>
<!ELEMENTid?EMPTY>
<!ATTLISTid?
val ID #REQUIRED>
<!ELEMENTtitle(#PCDATA)>
<!ATTLISTtitle?
desc NMTOKEN #REQUIRED
>
<!ELEMENTcontent(summary,text)>
<!ATTLISTcontent
about NMTOKENS #IMPLIED
>
<!ELEMENTsummary(#PCDATA)>
<!ELEMENTtext(#PCDATA)>
]>
<document>
<block>
<idval="a1" />
<titledesc="strictValue">title this</title>
<contentabout="could have whitespace">
<summary>the summary</summary>
<text>that's text</text>
</content>
</block>
<block>
<idval="a2" />
<titledesc="strictValue">title this</title>
<contentabout="could have whitespace">
<summary>the summary</summary>
<text>that's text</text>
</content>
</block>
<block>
<idval="a3" />
<titledesc="strictValue">title this</title>
<contentabout="could have whitespace">
<summary>the summary</summary>
<text>that's text</text>
</content>
</block>
</document>
3.4 IDREF
<?xmlversion="1.0"?encoding="UTF-8"?>
<!DOCTYPEcats?[
<!ELEMENTcats(cat)+>
<!ELEMENTcat(catSub)+>
<!ATTLISTcat?
id ID #REQUIRED?
idRef IDREF #IMPLIED
>
<!ELEMENTcatSub(#PCDATA)>
]>
<cats>
<catid='c1'?idRef="c2">
<catSub></catSub>
<catSub></catSub>
<catSub></catSub>
<catSub></catSub>
</cat>
<catid='c2'?idRef="c3">
<catSub></catSub>
<catSub></catSub>
<catSub></catSub>
<catSub></catSub>
</cat>
<catid='c3'>
<catSub></catSub>
<catSub></catSub>
<catSub></catSub>
<catSub></catSub>
</cat>
</cats>
3.5 ENTITY && ENTITIES
<?xmlversion="1.0"?encoding="UTF-8"?>
<!DOCTYPEdocument?[
<!ELEMENTdocument(block)+>
<!ELEMENTblock(#PCDATA)>
<!ENTITYsqCopySYSTEM?'s0.svg'>
<!ENTITYsqCopy1SYSTEM?'s0.svg'>
<!ENTITYsqCopy2SYSTEM?'s0.svg'>
<!ATTLISTblock?
sq ENTITY #IMPLIED
sqs ENTITIES #IMPLIED
>
]>
<document>
<blocksq="sqCopy">
</block>
<blocksqs="sqCopy sqCopy1 sqCopy2">
</block>
</document>
3.5.0 公式
3.5.0.1 内部带参数 ENTITY?
<!ENTITY%namedefinition>
3.5.1.1 外部带参数 ENTITY
<!ENTITY%NAMESYSTEMURI>
<!ENTITY%NAMEPUBLICFPIURI>
3.5.0.1 文本 ENTITY
<?xmlversion="1.0"?encoding="UTF-8"?>
<!DOCTYPEdocument?[
<!ELEMENTdocument(block)+>
<!ELEMENTblock(#PCDATA)>
<!ENTITYsqCopy1SYSTEM?'s0.svg'>
<!ENTITYsqCopy2SYSTEM?'s0.svg'>
<!ENTITYsqCopy?'&amp;copy;'?>
<!ATTLISTblock?
sq ENTITY #IMPLIED
sqs ENTITIES #IMPLIED
>
]>
<document>
<blocksq="sqCopy1">&sqCopy; </block>
<blocksqs="sqCopy1 sqCopy2">
</block>
</document>
3.5.2 自定义字符
<?xmlversion='1.0'?encoding='UTF-8'?>
<!DOCTYPEdocument?[
<!ELEMENTdocument(block)+>
<!ELEMENTblock(title,contents)>
<!ELEMENTtitle(#PCDATA)>
<!ELEMENTcontents(summary,text)>
<!ELEMENTsummary(#PCDATA)>
<!ELEMENTtext(#PCDATA)>
<!ENTITYat?'&#38;#64;'>
<!ENTITYsection?'&#38;#167;'>
<!ENTITYyuan?'&#38;#165;'>
<!ENTITYcopy?'&#38;#169;'>
<!ENTITYtreatmark?'&#38;#174;'>
<!ENTITYeuro?'&#38;#8364;'>
]>
<document>
<block>
<title></title>
<contents>
<summary>&yuan; &at; &copy; &treatmark; &section; &euro;</summary>
<text></text>
</contents>
</block>
</document>
3.5.3 引用外部文件
3.5.3.1 主文件
<?xmlversion='1.0'?encoding='UTF-8'?>
<!DOCTYPEdocument?[
<!ELEMENTdocument(header,block,footer)+>
<!ELEMENTheader(#PCDATA)>
<!ELEMENTblock(title,contents)>
<!ELEMENTtitle(#PCDATA)>
<!ELEMENTcontents(summary,text)>
<!ELEMENTsummary(#PCDATA)>
<!ELEMENTtext(#PCDATA)>
<!ELEMENTfooter(#PCDATA)>
<!ENTITYheaderSYSTEM?'x13Header.xml'>
<!ENTITYfooterSYSTEM?'x13Footer.xml'>
<!ENTITYat?'&#38;#64;'>
<!ENTITYsection?'&#38;#167;'>
<!ENTITYyuan?'&#38;#165;'>
<!ENTITYcopy?'&#38;#169;'>
<!ENTITYtreatmark?'&#38;#174;'>
<!ENTITYeuro?'&#38;#8364;'>
]>
<document>
<header>&header; <!--IE Only--></header>
<block>
<title></title>
<contents>
<summary>&yuan; &at; &copy; &treatmark; &section; &euro;</summary>
<text></text>
</contents>
</block>
<footer>&footer; <!--IE Only too--></footer>
</document>
3.5.3.2 x13Header.xml
<?xmlversion="1.0"?encoding="UTF-8"?>
'just a test, and this is header.'
3.5.3.3 x13Footer.xml
<?xmlversion="1.0"?encoding="UTF-8"?>
'just a test, and this is footer.'
3.5.4 带参数 ENTITY
3.5.4.1 内部 带参数 ENTITY
<?xmlversion="1.0"?encoding="UTF-8"?>
<!DOCTYPEdocument?[
<!ENTITY%ct?'<!ELEMENTcontents(summary,text)>'>
<!ELEMENTdocument(block)+>
<!ELEMENTblock(title,contents)>
<!ELEMENTtitle(#PCDATA)>
%ct;
<!ELEMENTsummary(#PCDATA)>
<!ELEMENTtext(#PCDATA)>
]>
<document>
<block>
<title>the title</title>
<contents>
<summary>the summary</summary>
<text>text go here</text>
</contents>
</block>
</document>
3.5.4.2 外部 带参数 ENTITY
3.5.4.2.1 x15.xml
<?xmlversion="1.0"?encoding="UTF-8"?>
<!DOCTYPEdocumentSYSTEM?'./x15.dtd'>
<document>
<block>
<title>the title</title>
<contents>
<summary>the summary</summary>
<text>text go here</text>
</contents>
<commentxmlns:cmt='http://www.w3c.org/ns/comment/'>
<cmt:block>
<cmt:nickname>the name</cmt:nickname>
<cmt:message>the message</cmt:message>
</cmt:block>
</comment>
</block>
</document>
3.5.4.2.2 x15.dtd
<?xmlversion="1.0"?encoding="UTF-8"?>
<!ENTITY%ct?'<!ELEMENTcontents(summary,text)>'>
<!ENTITY%cmt?'<!ELEMENTcomment(cmt:block)+>'>
<!ELEMENTdocument(block)+>
<!ELEMENTblock(title,contents,comment?)>
<!ELEMENTtitle(#PCDATA)>
%ct;
<!ELEMENTsummary(#PCDATA)>
<!ELEMENTtext(#PCDATA)>
%cmt;
<!ATTLISTcomment xmlns:cmt CDATA?#FIXED?'http://www.w3c.org/ns/comment/'>
<!ELEMENTcmt:block(cmt:nickname,cmt:message)>
<!ELEMENTcmt:nickname(#PCDATA)>
<!ELEMENTcmt:message(#PCDATA)>
3.6 NOTATION
<?xmlversion="1.0"?encoding="UTF-8"?>
<!DOCTYPEdocument?[
<!ELEMENTdocument(album)+>
<!ELEMENTalbum(subject,list,description)>
<!ATTLISTalbum?
id ID #REQUIRED>
<!ELEMENTsubject(#PCDATA)>
<!ELEMENTlist(img)+>
<!NOTATIONpngSYSTEM?'image/png'>
<!NOTATIONjpgSYSTEM?'image/jpeg'>
<!NOTATIONgifSYSTEM?'image/gif'>
<!NOTATIONsvgSYSTEM?'image/svg+xml'>
<!ELEMENTimg(#PCDATA)>
<!ATTLISTimg?
sSrc CDATA #IMPLIED
sType NOTATION (png | jpg | gif | svg) 'svg'
>
<!ELEMENTdescription(#PCDATA)>
]>
<document>
<albumid="a0">
<subject></subject>
<list>
<img?sSrc ='s0.svg'>the text</img>
<imgsSrc?='s1.svg'>the text</img>
<imgsSrc?='s2.svg'>the text</img>
</list>
<description></description>
</album>
<albumid="a1">
<subject></subject>
<list>
<imgsSrc?='s1.svg'>the text</img>
<imgsSrc?='s2.svg'>the text</img>
<imgsSrc?='s3.svg'>the text</img>
</list>
<description></description>
</album>
</document>
4 xml+dtd-CDATA
<?xmlversion="1.0"?encoding="UTF-8"?>
<!DOCTYPEdocument?[
<!ELEMENTdocument(text)*>
<!ELEMENTtext(#PCDATA)>
]>
<document>
<text>cdata section
<![CDATA[
<!DOCTYPEdocument?[
<!ELEMENTdocument(section)*>
<!ELEMENTsection(title,content)>
<!ELEMENTtitle(#PCDATA)>
<!ELEMENTcontent(summary,text)>
<!ELEMENTsummary(#PCDATA)>
<!ELEMENTtext(#PCDATA)>
<!ATTLISTsection id CDATA?#REQUIRED>
<!ATTLISTtitle id CDATA?#IMPLIED>
<!ATTLISTtitle xml:lang CDATA?#IMPLIED>
]>
<document>
<sectionid="ok">
<titleid="hasId"?xml:lang="zh-CN" >这是一个测试</title>
<content>
<summary></summary>
<text></text>
</content>
</section>
<sectionid="no">
<titlexml:lang="en-US">这是一个测试</title>
<content>
<summary></summary>
<text></text>
</content>
</section>
</document>
]]>
</text>
</document>
5 xml+dtd-EMPTY-ANY
<?xmlversion='1.0'?encoding='UTF-8'?>
<!DOCTYPEdocument?[
<!ELEMENTdocument(blocks)*>
<!ELEMENTblocks(title,content,comment?)>
<!ELEMENTtitle(#PCDATA)>
<!ELEMENTcontent(summary,text)>
<!ELEMENTsummary(#PCDATA)>
<!ELEMENTtext(#PCDATA)>
<!ELEMENTcomment?EMPTY>
<!ATTLISTcomment date CDATA?#IMPLIED>
]>
<document>
<blocks>
<title></title>
<content>
<summary></summary>
<text></text>
</content>
<commentdate='2006/12/09' />
</blocks>
<blocks>
<title></title>
<content>
<summary></summary>
<text></text>
</content>
</blocks>
</document>
6 多种方法定义 dtd
<?xmlversion='1.0'?encoding='UTF-8'?>
<!DOCTYPEdocument?[
<!ELEMENTdocument(block+)>
<!ELEMENTblock(title+,contents*,date?,id)>
<!ELEMENTtitle(#PCDATA)>
<!ELEMENTcontents(summary,text)>
<!ELEMENTsummary(#PCDATA)>
<!ELEMENTtext(#PCDATA)>
<!ELEMENTdate(#PCDATA)>
<!ELEMENTid(#PCDATA)>
]>
<document>
<block>
<title></title>
<title></title>
<contents>
<summary></summary>
<text></text>
</contents>
<id></id>
</block>
<block>
<title></title>
<date></date>
<id></id>
</block>
</document>
7 dtd 子定义
<?xmlversion="1.0"?encoding="UTF-8"?>
<!DOCTYPEdocument?[
<!ELEMENTdocument(block+)>
<!ELEMENTblock(title+,contents*,date?,(id,spid?,sbid*),(adti*|footer?))>
<!ELEMENTtitle(#PCDATA)>
<!ELEMENTcontents(summary,text)>
<!ELEMENTsummary(#PCDATA)>
<!ELEMENTtext(#PCDATA)>
<!ELEMENTdate(#PCDATA)>
<!ELEMENTid(#PCDATA)>
<!ELEMENTspid(#PCDATA)>
<!ELEMENTsbid(#PCDATA)>
<!ELEMENTadti(#PCDATA)>
<!ELEMENTfooter(#PCDATA)>
]>
<document>
<block>
<title/>
<title/>
<contents>
<summary/>
<text/>
</contents>
<id/>
<spid/>
<adti/>
</block>
<block>
<title/>
<date/>
<id/>
<footer/>
</block>
<block>
<title/>
<date/>
<id/>
<spid/>
<sbid/>
<footer/>
</block>
<block>
<title/>
<date/>
<id/>
<spid/>
<sbid/>
</block>
</document>
8 dtd 类型混用
<?xmlversion="1.0"?encoding="UTF-8"?>
<!DOCTYPEdocument?[
<!ELEMENTdocument(blocks)+ >
<!ELEMENTblocks(#PCDATA|subele)*>
<!ELEMENTsubele(#PCDATA)>
]>
<document>
<blocks>okay, test this.</blocks>
<blocks><subele>test sub element </subele></blocks>
</document>
9 外部 dtd
9.1 私有 dtd
9.1.1 简单私有 dtd
9.1.1.1 x6.xml
<?xmlversion="1.0"?encoding="UTF-8"?standalone='no' ?>
<!DOCTYPEdocumentSYSTEM?'./x6.dtd'>
<document>
<block>
<title/>
<title/>
<contents>
<summary/>
<text/>
</contents>
<id/>
<spid/>
<adti/>
</block>
<block>
<title/>
<date/>
<id/>
<footer/>
</block>
<block>
<title/>
<date/>
<id/>
<spid/>
<sbid/>
<footer/>
</block>
<block>
<<span s

热点排行