xml dtd 学习小结 By shawl.qiu

xml dtd 学习小结 By shawl.qiu

以前也有学习XML 的, 不过那时可能是水平不够, 看到DTD 就迷糊了.

这次学习 XML - DTD 我发现跟切菜一样容易, 只一天的时间, 感觉已经理解和掌握了 DTD 的用法.

究其原因, 可能要比较充分理解XML之前, 得有WEB编程的服务端与客户端的概念与基础; 理解 DTD, 正则基础则是必需的, 不过N久前, 俺的正则水平就自认为不错了:), 不过那时确实是到 DTD 就卡住了.

这个小结只是总结了尽可能全的 XML DTD 定义例子, 不过 INCLUDE && IGNORE 我还是没理解透.

目录:
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

内容:
  
  
  1. xml+dtd 定义实例 By shawl.qiu
  2. 1 简单的 xml+dtd
  3. 1.1 xml
  4. <?xml version="1.0" encoding="UTF-8"?>
  5. <?xml-stylesheet href="x2.css" type="text/css"?>
  6. <!DOCTYPE body [
  7. <!ELEMENT body (blocks)*>
  8. <!ELEMENT blocks (title, text)>
  9. <!ELEMENT title (#PCDATA)>
  10. <!ELEMENT text (#PCDATA)>
  11. ]>
  12. <body>
  13. <blocks>
  14. <title>title 1</title>
  15. <text>text 1</text>
  16. </blocks>
  17. <blocks>
  18. <title>title 2</title>
  19. <text>text 2</text>
  20. </blocks>
  21. <blocks>
  22. <title>title 2</title>
  23. <text>text 2</text>
  24. </blocks>
  25. </body>
  26. 1.2 css
  27. /* shawl.qiu CSS Document : shawl.qiu@gmail.com */
  28. block{background-color:gray;}
  29. title, text{display:block;}
  30. title{color:red;}
  31. text{color:blue;}
  32. text:first-letter{padding:0px 0px 0px 20px;}
  33. 2 简单的 xml+dtd 1
  34. <?xml version="1.0" encoding="UTF-8"?>
  35. <!DOCTYPE body [
  36. <!ELEMENT body (blocks)*>
  37. <!ELEMENT blocks (title, content) >
  38. <!ELEMENT title (#PCDATA)>
  39. <!ELEMENT content (summary, text)*>
  40. <!ELEMENT summary (#PCDATA)>
  41. <!ELEMENT text (#PCDATA)>
  42. ]>
  43. <body>
  44. <blocks>
  45. <title>this title 1</title>
  46. <content>
  47. <summary>summary text</summary>
  48. <text>the text</text>
  49. </content>
  50. </blocks>
  51. </body>
  52. 3 xml+dtd-定义属性
  53. <?xml version="1.0" encoding="UTF-8"?>
  54. <!DOCTYPE document [
  55. <!ELEMENT document (section)*>
  56. <!ELEMENT section (title, content)>
  57. <!ELEMENT title (#PCDATA)>
  58. <!ELEMENT content (summary, text)>
  59. <!ELEMENT summary (#PCDATA)>
  60. <!ELEMENT text (#PCDATA)>
  61. <!ATTLIST section id CDATA #REQUIRED>
  62. <!ATTLIST title id CDATA #IMPLIED>
  63. <!ATTLIST title xml:lang CDATA #IMPLIED>
  64. ]>
  65. <document>
  66. <section id="ok">
  67. <title id="hasId" xml:lang="zh-CN" >这是一个测试</title>
  68. <content>
  69. <summary></summary>
  70. <text></text>
  71. </content>
  72. </section>
  73. <section id="no">
  74. <title xml:lang="en-US">这是一个测试</title>
  75. <content>
  76. <summary></summary>
  77. <text></text>
  78. </content>
  79. </section>
  80. </document>
  81. 3.1 定义默认属性
  82. <?xml version="1.0" encoding="UTF-8"?>
  83. <!DOCTYPE document [
  84. <!ELEMENT document (block)+>
  85. <!ELEMENT block (id, title, contents, comment?, display)>
  86. <!ELEMENT id EMPTY>
  87. <!ATTLIST id
  88. idArticle CDATA "empty"
  89. idSpid CDATA "empty"
  90. idSbid CDATA "empty"
  91. >
  92. <!ELEMENT title (#PCDATA)>
  93. <!ELEMENT contents (summary, text)>
  94. <!ELEMENT summary (#PCDATA)>
  95. <!ELEMENT text (#PCDATA)>
  96. <!ELEMENT comment (idMsg, nick, msg)>
  97. <!ATTLIST comment
  98. switch CDATA #FIXED "on"
  99. >
  100. <!ELEMENT idMsg (#PCDATA)>
  101. <!ELEMENT nick (#PCDATA)>
  102. <!ELEMENT msg (#PCDATA)>
  103. <!ELEMENT display EMPTY>
  104. <!ATTLIST display
  105. show (yes|no) 'yes'
  106. >
  107. <!--枚举属性值-->
  108. ]>
  109. <document>
  110. <block>
  111. <id/>
  112. <title/>
  113. <contents>
  114. <summary/>
  115. <text/>
  116. </contents>
  117. <comment>
  118. <idMsg/>
  119. <nick/>
  120. <msg/>
  121. </comment>
  122. <display />
  123. </block>
  124. <block>
  125. <id idArticle="1" idSpid="1" idSbid="1"/>
  126. <title/>
  127. <contents>
  128. <summary/>
  129. <text/>
  130. </contents>
  131. <comment>
  132. <idMsg/>
  133. <nick/>
  134. <msg/>
  135. </comment>
  136. <display show="no" />
  137. </block>
  138. </document>
  139. 3.2 NMTOKEN && NMTOKENS
  140. <?xml version="1.0" encoding="UTF-8"?>
  141. <!DOCTYPE document [
  142. <!ELEMENT document (block)+>
  143. <!ELEMENT block (title, content)>
  144. <!ELEMENT title (#PCDATA)>
  145. <!ATTLIST title
  146. desc NMTOKEN #REQUIRED
  147. >
  148. <!ELEMENT content (summary, text)>
  149. <!ATTLIST content
  150. about NMTOKENS #IMPLIED
  151. >
  152. <!ELEMENT summary (#PCDATA)>
  153. <!ELEMENT text (#PCDATA)>
  154. ]>
  155. <document>
  156. <block>
  157. <title desc="strictValue">title this</title>
  158. <content about="could have whitespace">
  159. <summary>the summary</summary>
  160. <text>that's text</text>
  161. </content>
  162. </block>
  163. </document>
  164. 3.3 ID
  165. <?xml version="1.0" encoding="UTF-8"?>
  166. <!DOCTYPE document [
  167. <!ELEMENT document (block)+>
  168. <!ELEMENT block (id, title, content)>
  169. <!ELEMENT id EMPTY>
  170. <!ATTLIST id
  171. val ID #REQUIRED>
  172. <!ELEMENT title (#PCDATA)>
  173. <!ATTLIST title
  174. desc NMTOKEN #REQUIRED
  175. >
  176. <!ELEMENT content (summary, text)>
  177. <!ATTLIST content
  178. about NMTOKENS #IMPLIED
  179. >
  180. <!ELEMENT summary (#PCDATA)>
  181. <!ELEMENT text (#PCDATA)>
  182. ]>
  183. <document>
  184. <block>
  185. <id val="a1" />
  186. <title desc="strictValue">title this</title>
  187. <content about="could have whitespace">
  188. <summary>the summary</summary>
  189. <text>that's text</text>
  190. </content>
  191. </block>
  192. <block>
  193. <id val="a2" />
  194. <title desc="strictValue">title this</title>
  195. <content about="could have whitespace">
  196. <summary>the summary</summary>
  197. <text>that's text</text>
  198. </content>
  199. </block>
  200. <block>
  201. <id val="a3" />
  202. <title desc="strictValue">title this</title>
  203. <content about="could have whitespace">
  204. <summary>the summary</summary>
  205. <text>that's text</text>
  206. </content>
  207. </block>
  208. </document>
  209. 3.4 IDREF
  210. <?xml version="1.0" encoding="UTF-8"?>
  211. <!DOCTYPE cats [
  212. <!ELEMENT cats (cat)+>
  213. <!ELEMENT cat (catSub)+>
  214. <!ATTLIST cat
  215. id ID #REQUIRED
  216. idRef IDREF #IMPLIED
  217. >
  218. <!ELEMENT catSub (#PCDATA)>
  219. ]>
  220. <cats>
  221. <cat id='c1' idRef="c2">
  222. <catSub></catSub>
  223. <catSub></catSub>
  224. <catSub></catSub>
  225. <catSub></catSub>
  226. </cat>
  227. <cat id='c2' idRef="c3">
  228. <catSub></catSub>
  229. <catSub></catSub>
  230. <catSub></catSub>
  231. <catSub></catSub>
  232. </cat>
  233. <cat id='c3'>
  234. <catSub></catSub>
  235. <catSub></catSub>
  236. <catSub></catSub>
  237. <catSub></catSub>
  238. </cat>
  239. </cats>
  240. 3.5 ENTITY && ENTITIES
  241. <?xml version="1.0" encoding="UTF-8"?>
  242. <!DOCTYPE document [
  243. <!ELEMENT document (block)+>
  244. <!ELEMENT block (#PCDATA)>
  245. <!ENTITY sqCopy SYSTEM 's0.svg'>
  246. <!ENTITY sqCopy1 SYSTEM 's0.svg'>
  247. <!ENTITY sqCopy2 SYSTEM 's0.svg'>
  248. <!ATTLIST block
  249. sq ENTITY #IMPLIED
  250. sqs ENTITIES #IMPLIED
  251. >
  252. ]>
  253. <document>
  254. <block sq="sqCopy">
  255. </block>
  256. <block sqs="sqCopy sqCopy1 sqCopy2">
  257. </block>
  258. </document>
  259. 3.5.0 公式
  260. 3.5.0.1 内部带参数 ENTITY
  261. <!ENTITY % name definition>
  262. 3.5.1.1 外部带参数 ENTITY
  263. <!ENTITY % NAME SYSTEM URI>
  264. <!ENTITY % NAME PUBLIC FPI URI>
  265. 3.5.0.1 文本 ENTITY
  266. <?xml version="1.0" encoding="UTF-8"?>
  267. <!DOCTYPE document [
  268. <!ELEMENT document (block)+>
  269. <!ELEMENT block (#PCDATA)>
  270. <!ENTITY sqCopy1 SYSTEM 's0.svg'>
  271. <!ENTITY sqCopy2 SYSTEM 's0.svg'>
  272. <!ENTITY sqCopy '&amp;copy;' >
  273. <!ATTLIST block
  274. sq ENTITY #IMPLIED
  275. sqs ENTITIES #IMPLIED
  276. >
  277. ]>
  278. <document>
  279. <block sq="sqCopy1">&sqCopy; </block>
  280. <block sqs="sqCopy1 sqCopy2">
  281. </block>
  282. </document>
  283. 3.5.2 自定义字符
  284. <?xml version='1.0' encoding='UTF-8'?>
  285. <!DOCTYPE document [
  286. <!ELEMENT document (block)+>
  287. <!ELEMENT block (title, contents)>
  288. <!ELEMENT title (#PCDATA)>
  289. <!ELEMENT contents (summary, text)>
  290. <!ELEMENT summary (#PCDATA)>
  291. <!ELEMENT text (#PCDATA)>
  292. <!ENTITY at '&#38;#64;'>
  293. <!ENTITY section '&#38;#167;'>
  294. <!ENTITY yuan '&#38;#165;'>
  295. <!ENTITY copy '&#38;#169;'>
  296. <!ENTITY treatmark '&#38;#174;'>
  297. <!ENTITY euro '&#38;#8364;'>
  298. ]>
  299. <document>
  300. <block>
  301. <title></title>
  302. <contents>
  303. <summary>&yuan; &at; &copy; &treatmark; &section; &euro;</summary>
  304. <text></text>
  305. </contents>
  306. </block>
  307. </document>
  308. 3.5.3 引用外部文件
  309. 3.5.3.1 主文件
  310. <?xml version='1.0' encoding='UTF-8'?>
  311. <!DOCTYPE document [
  312. <!ELEMENT document (header, block, footer)+>
  313. <!ELEMENT header (#PCDATA)>
  314. <!ELEMENT block (title, contents)>
  315. <!ELEMENT title (#PCDATA)>
  316. <!ELEMENT contents (summary, text)>
  317. <!ELEMENT summary (#PCDATA)>
  318. <!ELEMENT text (#PCDATA)>
  319. <!ELEMENT footer (#PCDATA)>
  320. <!ENTITY header SYSTEM 'x13Header.xml'>
  321. <!ENTITY footer SYSTEM 'x13Footer.xml'>
  322. <!ENTITY at '&#38;#64;'>
  323. <!ENTITY section '&#38;#167;'>
  324. <!ENTITY yuan '&#38;#165;'>
  325. <!ENTITY copy '&#38;#169;'>
  326. <!ENTITY treatmark '&#38;#174;'>
  327. <!ENTITY euro '&#38;#8364;'>
  328. ]>
  329. <document>
  330. <header>&header; <!--IE Only--></header>
  331. <block>
  332. <title></title>
  333. <contents>
  334. <summary>&yuan; &at; &copy; &treatmark; &section; &euro;</summary>
  335. <text></text>
  336. </contents>
  337. </block>
  338. <footer>&footer; <!--IE Only too--></footer>
  339. </document>
  340. 3.5.3.2 x13Header.xml
  341. <?xml version="1.0" encoding="UTF-8"?>
  342. 'just a test, and this is header.'
  343. 3.5.3.3 x13Footer.xml
  344. <?xml version="1.0" encoding="UTF-8"?>
  345. 'just a test, and this is footer.'
  346. 3.5.4 带参数 ENTITY
  347. 3.5.4.1 内部 带参数 ENTITY
  348. <?xml version="1.0" encoding="UTF-8"?>
  349. <!DOCTYPE document [
  350. <!ENTITY % ct '<!ELEMENT contents (summary, text)>'>
  351. <!ELEMENT document (block)+>
  352. <!ELEMENT block (title, contents)>
  353. <!ELEMENT title (#PCDATA)>
  354. %ct;
  355. <!ELEMENT summary (#PCDATA)>
  356. <!ELEMENT text (#PCDATA)>
  357. ]>
  358. <document>
  359. <block>
  360. <title>the title</title>
  361. <contents>
  362. <summary>the summary</summary>
  363. <text>text go here</text>
  364. </contents>
  365. </block>
  366. </document>
  367. 3.5.4.2 外部 带参数 ENTITY
  368. 3.5.4.2.1 x15.xml
  369. <?xml version="1.0" encoding="UTF-8"?>
  370. <!DOCTYPE document SYSTEM './x15.dtd'>
  371. <document>
  372. <block>
  373. <title>the title</title>
  374. <contents>
  375. <summary>the summary</summary>
  376. <text>text go here</text>
  377. </contents>
  378. <comment xmlns:cmt='http://www.w3c.org/ns/comment/'>
  379. <cmt:block>
  380. <cmt:nickname>the name</cmt:nickname>
  381. <cmt:message>the message</cmt:message>
  382. </cmt:block>
  383. </comment>
  384. </block>
  385. </document>
  386. 3.5.4.2.2 x15.dtd
  387. <?xml version="1.0" encoding="UTF-8"?>
  388. <!ENTITY % ct '<!ELEMENT contents (summary, text)>'>
  389. <!ENTITY % cmt '<!ELEMENT comment (cmt:block)+>'>
  390. <!ELEMENT document (block)+>
  391. <!ELEMENT block (title, contents, comment?)>
  392. <!ELEMENT title (#PCDATA)>
  393. %ct;
  394. <!ELEMENT summary (#PCDATA)>
  395. <!ELEMENT text (#PCDATA)>
  396. %cmt;
  397. <!ATTLIST comment xmlns:cmt CDATA #FIXED 'http://www.w3c.org/ns/comment/'>
  398. <!ELEMENT cmt:block (cmt:nickname, cmt:message)>
  399. <!ELEMENT cmt:nickname (#PCDATA)>
  400. <!ELEMENT cmt:message (#PCDATA)>
  401. 3.6 NOTATION
  402. <?xml version="1.0" encoding="UTF-8"?>
  403. <!DOCTYPE document [
  404. <!ELEMENT document (album)+>
  405. <!ELEMENT album (subject ,list, description)>
  406. <!ATTLIST album
  407. id ID #REQUIRED>
  408. <!ELEMENT subject (#PCDATA)>
  409. <!ELEMENT list (img)+>
  410. <!NOTATION png SYSTEM 'image/png'>
  411. <!NOTATION jpg SYSTEM 'image/jpeg'>
  412. <!NOTATION gif SYSTEM 'image/gif'>
  413. <!NOTATION svg SYSTEM 'image/svg+xml'>
  414. <!ELEMENT img (#PCDATA)>
  415. <!ATTLIST img
  416. sSrc CDATA #IMPLIED
  417. sType NOTATION (png | jpg | gif | svg) 'svg'
  418. >
  419. <!ELEMENT description (#PCDATA)>
  420. ]>
  421. <document>
  422. <album id="a0">
  423. <subject></subject>
  424. <list>
  425. <img sSrc ='s0.svg'>the text</img>
  426. <img sSrc ='s1.svg'>the text</img>
  427. <img sSrc ='s2.svg'>the text</img>
  428. </list>
  429. <description></description>
  430. </album>
  431. <album id="a1">
  432. <subject></subject>
  433. <list>
  434. <img sSrc ='s1.svg'>the text</img>
  435. <img sSrc ='s2.svg'>the text</img>
  436. <img sSrc ='s3.svg'>the text</img>
  437. </list>
  438. <description></description>
  439. </album>
  440. </document>
  441. 4 xml+dtd-CDATA
  442. <?xml version="1.0" encoding="UTF-8"?>
  443. <!DOCTYPE document [
  444. <!ELEMENT document (text)*>
  445. <!ELEMENT text (#PCDATA)>
  446. ]>
  447. <document>
  448. <text>cdata section
  449. <![CDATA[
  450. <!DOCTYPE document [
  451. <!ELEMENT document (section)*>
  452. <!ELEMENT section (title, content)>
  453. <!ELEMENT title (#PCDATA)>
  454. <!ELEMENT content (summary, text)>
  455. <!ELEMENT summary (#PCDATA)>
  456. <!ELEMENT text (#PCDATA)>
  457. <!ATTLIST section id CDATA #REQUIRED>
  458. <!ATTLIST title id CDATA #IMPLIED>
  459. <!ATTLIST title xml:lang CDATA #IMPLIED>
  460. ]>
  461. <document>
  462. <section id="ok">
  463. <title id="hasId" xml:lang="zh-CN" >这是一个测试</title>
  464. <content>
  465. <summary></summary>
  466. <text></text>
  467. </content>
  468. </section>
  469. <section id="no">
  470. <title xml:lang="en-US">这是一个测试</title>
  471. <content>
  472. <summary></summary>
  473. <text></text>
  474. </content>
  475. </section>
  476. </document>
  477. ]]>
  478. </text>
  479. </document>
  480. 5 xml+dtd-EMPTY-ANY
  481. <?xml version='1.0' encoding='UTF-8'?>
  482. <!DOCTYPE document [
  483. <!ELEMENT document (blocks)*>
  484. <!ELEMENT blocks (title, content, comment?)>
  485. <!ELEMENT title (#PCDATA)>
  486. <!ELEMENT content (summary, text)>
  487. <!ELEMENT summary (#PCDATA)>
  488. <!ELEMENT text (#PCDATA)>
  489. <!ELEMENT comment EMPTY>
  490. <!ATTLIST comment date CDATA #IMPLIED>
  491. ]>
  492. <document>
  493. <blocks>
  494. <title></title>
  495. <content>
  496. <summary></summary>
  497. <text></text>
  498. </content>
  499. <comment date='2006/12/09' />
  500. </blocks>
  501. <blocks>
  502. <title></title>
  503. <content>
  504. <summary></summary>
  505. <text></text>
  506. </content>
  507. </blocks>
  508. </document>
  509. 6 多种方法定义 dtd
  510. <?xml version='1.0' encoding='UTF-8'?>
  511. <!DOCTYPE document [
  512. <!ELEMENT document (block+)>
  513. <!ELEMENT block (title+, contents*, date?, id)>
  514. <!ELEMENT title (#PCDATA)>
  515. <!ELEMENT contents (summary, text)>
  516. <!ELEMENT summary (#PCDATA)>
  517. <!ELEMENT text (#PCDATA)>
  518. <!ELEMENT date (#PCDATA)>
  519. <!ELEMENT id (#PCDATA)>
  520. ]>
  521. <document>
  522. <block>
  523. <title></title>
  524. <title></title>
  525. <contents>
  526. <summary></summary>
  527. <text></text>
  528. </contents>
  529. <id></id>
  530. </block>
  531. <block>
  532. <title></title>
  533. <date></date>
  534. <id></id>
  535. </block>
  536. </document>
  537. 7 dtd 子定义
  538. <?xml version="1.0" encoding="UTF-8"?>
  539. <!DOCTYPE document [
  540. <!ELEMENT document (block+)>
  541. <!ELEMENT block (title+, contents*, date?, (id, spid?, sbid*), (adti* | footer?))>
  542. <!ELEMENT title (#PCDATA)>
  543. <!ELEMENT contents (summary, text)>
  544. <!ELEMENT summary (#PCDATA)>
  545. <!ELEMENT text (#PCDATA)>
  546. <!ELEMENT date (#PCDATA)>
  547. <!ELEMENT id (#PCDATA)>
  548. <!ELEMENT spid (#PCDATA)>
  549. <!ELEMENT sbid (#PCDATA)>
  550. <!ELEMENT adti (#PCDATA)>
  551. <!ELEMENT footer (#PCDATA)>
  552. ]>
  553. <document>
  554. <block>
  555. <title/>
  556. <title/>
  557. <contents>
  558. <summary/>
  559. <text/>
  560. </contents>
  561. <id/>
  562. <spid/>
  563. <adti/>
  564. </block>
  565. <block>
  566. <title/>
  567. <date/>
  568. <id/>
  569. <footer/>
  570. </block>
  571. <block>
  572. <title/>
  573. <date/>
  574. <id/>
  575. <spid/>
  576. <sbid/>
  577. <footer/>
  578. </block>
  579. <block>
  580. <title/>
  581. <date/>
  582. <id/>
  583. <spid/>
  584. <sbid/>
  585. </block>
  586. </document>
  587. 8 dtd 类型混用
  588. <?xml version="1.0" encoding="UTF-8"?>
  589. <!DOCTYPE document [
  590. <!ELEMENT document (blocks)+ >
  591. <!ELEMENT blocks (#PCDATA | subele)*>
  592. <!ELEMENT subele (#PCDATA)>
  593. ]>
  594. <document>
  595. <blocks>okay, test this.</blocks>
  596. <blocks><subele>test sub element </subele></blocks>
  597. </document>
  598. 9 外部 dtd
  599. 9.1 私有 dtd
  600. 9.1.1 简单私有 dtd
  601. 9.1.1.1 x6.xml
  602. <?xml version="1.0" encoding="UTF-8" standalone='no' ?>
  603. <!DOCTYPE document SYSTEM './x6.dtd'>
  604. <document>
  605. <block>
  606. <title/>
  607. <title/>
  608. <contents>
  609. <summary/>
  610. <text/>
  611. </contents>
  612. <id/>
  613. <spid/>
  614. <adti/>
  615. </block>
  616. <block>
  617. <title/>
  618. <date/>
  619. <id/>
  620. <footer/>
  621. </block>
  622. <block>
  623. <title/>
  624. <date/>
  625. <id/>
  626. <spid/>
  627. <sbid/>
  628. <footer/>
  629. </block>
  630. <block>
  631. <title/>
  632. <date/>
  633. <id/>
  634. <spid/>
  635. <sbid/>
  636. </block>
  637. </document>
  638. 9.1.1.2 x6.dtd
  639. <!ELEMENT document (block+)>
  640. <!ELEMENT block (title+, contents*, date?, (id, spid?, sbid*), (adti* | footer?))>
  641. <!ELEMENT title (#PCDATA)>
  642. <!ELEMENT contents (summary, text)>
  643. <!ELEMENT summary (#PCDATA)>
  644. <!ELEMENT text (#PCDATA)>
  645. <!ELEMENT date (#PCDATA)>
  646. <!ELEMENT id (#PCDATA)>
  647. <!ELEMENT spid (#PCDATA)>
  648. <!ELEMENT sbid (#PCDATA)>
  649. <!ELEMENT adti (#PCDATA)>
  650. <!ELEMENT footer (#PCDATA)>
  651. 10 xml+dtd-xmlns
  652. <?xml version='1.0' encoding='UTF-8' standalone='yes'?>
  653. <!DOCTYPE ts:document [
  654. <!ELEMENT ts:document (ts:block)+>
  655. <!ATTLIST ts:document xmlns:ts CDATA #FIXED 'http://www.w3c.org/ns/test' >
  656. <!ELEMENT ts:block (#PCDATA | ts:subele)*>
  657. <!ELEMENT ts:subele (#PCDATA)>
  658. ]>
  659. <ts:document xmlns:ts='http://www.w3c.org/ns/test'>
  660. <ts:block>just a test</ts:block>
  661. <ts:block><ts:subele>sub element</ts:subele></ts:block>
  662. </ts:document>
  663. 10.1 xml+dtd - xmlns 子名称空间
  664. <?xml version="1.0" encoding="UTF-8"?>
  665. <!DOCTYPE document [
  666. <!ENTITY % ct '<!ELEMENT contents (summary, text)>'>
  667. <!ELEMENT document (block)+>
  668. <!ELEMENT block (title, contents, comment?)>
  669. <!ELEMENT title (#PCDATA)>
  670. %ct;
  671. <!ELEMENT summary (#PCDATA)>
  672. <!ELEMENT text (#PCDATA)>
  673. <!ELEMENT comment (cmt:block)+>
  674. <!ATTLIST comment xmlns:cmt CDATA #FIXED 'http://www.w3c.org/ns/comment/'>

  675. <!ELEMENT cmt:block (cmt:nickname, cmt:message)>
  676. <!ELEMENT cmt:nickname (#PCDATA)>
  677. <!ELEMENT cmt:message (#PCDATA)>
  678. ]>
  679. <document>
  680. <block>
  681. <title>the title</title>
  682. <contents>
  683. <summary>the summary</summary>
  684. <text>text go here</text>
  685. </contents>
  686. <comment xmlns:cmt='http://www.w3c.org/ns/comment/'>
  687. <cmt:block>
  688. <cmt:nickname>the name</cmt:nickname>
  689. <cmt:message>the message</cmt:message>
  690. </cmt:block>
  691. </comment>
  692. </block>
  693. </document>
  694. 11 INCLUDE && IGNORE
  695. 11.0 公式
  696. 11.0.1 INCLUDE
  697. <![ INCLUDE [DTD Section]]>
  698. 11.0.2 IGNORE
  699. <![ IGNORE [DTD Section]]>
  700. 11.1 dtd 定义
  701. <?xml version="1.0" encoding="UTF-8"?>
  702. <![ IGNORE [
  703. <!ELEMENT text (#PCDATA)>
  704. <!ELEMENT comment (cmt:block)>
  705. ]]>
  706. <![ INCLUDE [
  707. <!ELEMENT addition (#PCDATA)>
  708. ]]>
  709. <!ENTITY % ct '<!ELEMENT contents (summary, text)>'>
  710. <!ENTITY % cmt '<!ELEMENT comment (cmt:block)+>'>
  711. <!ELEMENT document (block)+>
  712. <!ELEMENT block (title, contents, comment?)>
  713. <!ELEMENT title (#PCDATA)>
  714. %ct;
  715. <!ELEMENT summary (#PCDATA)>
  716. <!ELEMENT text (#PCDATA)>
  717. %cmt;
  718. <!ATTLIST comment xmlns:cmt CDATA #FIXED 'http://www.w3c.org/ns/comment/'>
  719. <!ELEMENT cmt:block (cmt:nickname, cmt:message)>
  720. <!ELEMENT cmt:nickname (#PCDATA)>
  721. <!ELEMENT cmt:message (#PCDATA)>

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值