DTD DTD xml version1 0 encodingShiftJIS ELEMENT BOOKLIST
DTD
DTDの例 <? xml version="1. 0" encoding="Shift_JIS"? > <!ELEMENT BOOKLIST (BOOK+)> <!ELEMENT BOOK ( TITLE, AUTHOR, PUBLISHER)> <!ELEMENT TITLE (#PCDATA)> <!ELEMENT AUTHOR (#PCDATA)> <!ELEMENT PUBLISHER (#PCDATA)>
DTDを使ったXML文書 <? xml version="1. 0" encoding="Shift_JIS"? > <!DOCTYPE BOOKLIST SYSTEM "BOOKLIST. dtd"> <BOOKLIST> <BOOK> <TITLE>情報メディア論</TITLE> <AUTHOR>丸山不二夫 編著</AUTHOR> <PUBLISHER>八千代出版</PUBLISHER> </BOOK> ……… </BOOKLIST>
XMLの限界 (1) XMLらしくない記法 n 「要素を組み合わせる」という記法ではな いので、わかりにくい。 <!ELEMENT BOOKLIST (BOOK+)> <!ELEMENT BOOK ( TITLE, AUTHOR, PUBLISHER)> <!ELEMENT TITLE (#PCDATA)>
XML Schema とは何か
単純な XML Schema <? xml version="1. 0"? > <xsd: schema xmlns: xsd="http: //www. w 3. org/2001/XMLSchema" target. Namespace= "http: //www. wakhok. ac. jp/~tomoharu/students" xmlns: st= "http: //www. wakhok. ac. jp/~tomoharu/students"> <xsd: element name=“name” type="xsd: string"/> </xsd: schema>
もっと単純化すると <? xml version="1. 0"? > <xsd: schema> <xsd: element name=“name” type="xsd: string"/> </xsd: schema>
XML Schema 自体の 名前空間の指定 <xsd: schema xmlns: xsd="http: //www. w 3. org/2001/XMLSchema" target. Namespace= "http: //www. wakhok. ac. jp/~tomoharu/students" xmlns: st= "http: //www. wakhok. ac. jp/~tomoharu/students"> <xsd: element name=“name” type="xsd: string"/> </xsd: schema>
この XML Schema の 名前空間の指定 <xsd: schema xmlns: xsd="http: //www. w 3. org/2001/XMLSchema" target. Namespace= "http: //www. wakhok. ac. jp/~tomoharu/students" xmlns: st= "http: //www. wakhok. ac. jp/~tomoharu/students"> <xsd: element name=“name” type="xsd: string"/> </xsd: schema>
このXML Schema を使った XML インスタンス <? xml version="1. 0"? > <st: name xmlns: st= "http: //www. wakhok. ac. jp/~tomoharu/students" xmlns: xsi= “http: //www. w 3. org/2001/XMLSchema-instance” xsi: schema. Location= "http: //www. wakhok. ac. jp/~tomoharu/students sample 01. xsd"> 安藤友晴 </st: name>
XML Schema の指定 (1) <? xml version="1. 0"? > <st: name xmlns: st= "http: //www. wakhok. ac. jp/~tomoharu/students" xmlns: xsi= “http: //www. w 3. org/2001/XMLSchema-instance” xsi: schema. Location= "http: //www. wakhok. ac. jp/~tomoharu/students sample 01. xsd"> 安藤友晴 </st: name>
XML Schema の指定 (2) xsi: schema. Location= "http: //www. wakhok. ac. jp/~tomoharu/students sample 01. xsd"> n XML Schema の URI n ファイルの実体がある場所でない XML Schema のファイル n sample 01. xsd n カレントディレクトリにある n n http: //www. wakhok. ac. jp/~tomoharu/students
このXML Schema の 名前空間 (1) <? xml version="1. 0"? > <st: name xmlns: st= "http: //www. wakhok. ac. jp/~tomoharu/students" xmlns: xsi= “http: //www. w 3. org/2001/XMLSchema-instance” xsi: schema. Location= "http: //www. wakhok. ac. jp/~tomoharu/students sample 01. xsd"> 安藤友晴 </st: name>
このXML Schema の 名前空間 (2) n n n http: //www. wakhok. ac. jp/~tomoharu/st udents という URI を持つ XML Schema で定義されているタグは st という接頭辞を持つ 例) n <st: name>安藤友晴</st: name>
XSV の使用例 C: Home200405>xsv sample 01. xml <? xml version='1. 0'? > <xsv xmlns="http: //www. w 3. org/2000/05/xsv" doc. Elt="{http: //www. wakhok. ac. jp/~tomoharu/students}name" instance. Assessed="true" instance. Errors="0" root. Type="string" schema. Errors="0" schema. Locs="http: //www. wakhok. ac. jp/~tomoharu/students -> sample 01. xsd" target="file: ///C: /Home/200405/sample 01. xml" validation="strict" version="XSV 2. 7 -1 of 2004/04/01 13: 40: 50"> <schema. Doc. Attempt URI="file: ///C: /Home/200405/sample 01. xsd" namespace="http: //www. wakhok. ac. jp/~tomoharu/students" outcome="success" source="schema. Loc"/> </xsv>
参考文献・URL n Extensible Markup Language (XML) 1. 0 (Third Edition) n n n http: //www. w 3. org/TR/REC-xml/ XML 1. 0 の仕様書です。 W 3 C XML Schema n n http: //www. w 3. org/XML/Schema XML Schema の仕様書など。
- Slides: 33