iT邦幫忙

DAY 12
2

emacs的30天學習筆記系列 第 12

emacs 做中學第十二天:xml dtd 的一個小測試

邦友antijava的XML系列,看了之後,興起了想要實驗的念頭.

最近裝了有名的libxml2,裏面有附小工具,xmllint.

$ xmllint --valid insideDTD.xml
<?xml version="1.0"?>

<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
Don't forget me this weekend
</note>

以上是格式良好(well form)的情況.

$ xmllint --valid insideDTD.xml
insideDTD.xml:15: element note: <strong>validity error</strong> : Element note content does not follow the DTD, expecting (to , from , heading , body , comment), <strong>got (to from heading body )</strong>
</note>
       ^
<?xml version="1.0"?>

<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
<!ELEMENT <strong>comment</strong> (#PCDATA)>
]>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
Don't forget me this weekend
</note>

粗體字的部分,因為多定義了一個欄位,導致valid(有效)檢查ERROR.

小結:emacs可編xml文件.<>不對稱時,會秀出紅色.
xmllint (line tool)還支援shell互動模式,可惜筆者,搞參數
(OPTION)就搞不出名堂.網上大多是libxml2程式庫的使用,對這個工具xmllint著墨很少.有想到一些實驗,實作不出來.


上一篇
emacs 做中學第十一天: Synaptic套件庫的更新
下一篇
emacs 做中學第十三天:關於make及Makefile
系列文
emacs的30天學習筆記38
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 則留言

0
chiounan
iT邦研究生 1 級 ‧ 2011-10-19 09:16:07

拍手加油就靠你了

我要留言

立即登入留言