XML Schema xml version1 0 xsd schema xmlns

  • Slides: 42
Download presentation

XML Schema の例 <? xml version="1. 0"? > <xsd: schema xmlns: xsd="http: //www. w

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="student"> <xsd: complex. Type> <xsd: sequence> <xsd: element ref="st: family. Name" /> <xsd: element ref="st: given. Name" /> <xsd: element ref="st: email" min. Occurs="0" max. Occurs="2" /> </xsd: sequence> </xsd: complex. Type> </xsd: element> <xsd: element name="family. Name" type="xsd: string" /> <xsd: element name="given. Name" type="xsd: string" /> <xsd: element name="email" type="xsd: string" /> </xsd: schema>

min. Occurs 属性と max. Occurs 属性の指定 <xsd: element ref="st: email" min. Occurs="0" max. Occurs="2"

min. Occurs 属性と max. Occurs 属性の指定 <xsd: element ref="st: email" min. Occurs="0" max. Occurs="2" /> n e-mail 要素が0回以上、2回以下出現する。

XML Schema に適合する インスタンス (1) <st: family. Name>安藤</st: family. Name> <st: given. Name>友晴</st: given.

XML Schema に適合する インスタンス (1) <st: family. Name>安藤</st: family. Name> <st: given. Name>友晴</st: given. Name> <st: email> tomoharu@wakhok. ac. jp </st: email>

XML Schema に適合する インスタンス (2) <st: family. Name>安藤</st: family. Name> <st: given. Name>友晴</st: given.

XML Schema に適合する インスタンス (2) <st: family. Name>安藤</st: family. Name> <st: given. Name>友晴</st: given. Name> n email 要素がなくてもよい。

XML Schema に適合しない例 <st: family. Name>安藤</st: family. Name> <st: given. Name>友晴</st: given. Name> <st:

XML Schema に適合しない例 <st: family. Name>安藤</st: family. Name> <st: given. Name>友晴</st: given. Name> <st: email> tomoharu@wakhok. ac. jp </st: email> <st: email>aaa@b. com</st: email> <st: email>bbb@hoge. jp</st: email>

sequence

sequence

<xsd: sequence> 要素が順番に出現する <xsd: sequence> <xsd: element name="family. Name“ type="xsd: string"/> <xsd: element name="given.

<xsd: sequence> 要素が順番に出現する <xsd: sequence> <xsd: element name="family. Name“ type="xsd: string"/> <xsd: element name="given. Name" type="xsd: string" /> </xsd: sequence> n n family. Name 要素が出てから given. Name 要素が出現 順番の変更や要素の省略は許されない

XML Schema に適合する例 <st: student> <st: family. Name>安藤</st: family. Name> <st: given. Name>友晴</st: given.

XML Schema に適合する例 <st: student> <st: family. Name>安藤</st: family. Name> <st: given. Name>友晴</st: given. Name> </st: student>

XML Schema に 適合しない例 (1) <st: student> <st: given. Name>友晴</st: given. Name> <st: family.

XML Schema に 適合しない例 (1) <st: student> <st: given. Name>友晴</st: given. Name> <st: family. Name>安藤</st: family. Name> </st: student> n given. Name と family. Name が逆

XML Schema に 適合しない例 (2) <st: student> <st: family. Name>安藤</st: family. Name> </st: student>

XML Schema に 適合しない例 (2) <st: student> <st: family. Name>安藤</st: family. Name> </st: student> n given. Name がない

all

all

XML Schema に適合する例 <st: student> <st: given. Name>友晴</st: given. Name> <st: email> tomoharu@wakhok. ac.

XML Schema に適合する例 <st: student> <st: given. Name>友晴</st: given. Name> <st: email> tomoharu@wakhok. ac. jp </st: email> <st: family. Name>安藤</st: family. Name> </st: student>

ダメな XML Schema <xsd: all> <xsd: element ref="st: family. Name" /> <xsd: element ref="st:

ダメな XML Schema <xsd: all> <xsd: element ref="st: family. Name" /> <xsd: element ref="st: given. Name" /> <xsd: element ref="st: email“ min. Occurs=“ 0” max. Occurs=“ 3” /> </xsd: all> n max. Occurs = “ 3” という指定はできない。

choice

choice

<xsd: choice> どれか1つの要素が出現する <xsd: choice> <xsd: element ref="it: book" /> <xsd: element ref="it: cd"

<xsd: choice> どれか1つの要素が出現する <xsd: choice> <xsd: element ref="it: book" /> <xsd: element ref="it: cd" /> <xsd: element ref="it: dvd" /> </xsd: choice> n 子要素のうち、どれか1つが出現する

XML Schema に適合する例 <it: item> <it: book>蹴りたい背中</it: book> </it: item>

XML Schema に適合する例 <it: item> <it: book>蹴りたい背中</it: book> </it: item>

XML Schema の例 <xsd: element name="student"> <xsd: complex. Type> <xsd: sequence> <xsd: element ref="st:

XML Schema の例 <xsd: element name="student"> <xsd: complex. Type> <xsd: sequence> <xsd: element ref="st: family. Name" /> <xsd: element ref="st: given. Name" /> </xsd: sequence> <xsd: attribute name=“number” type="xsd: string" /> </xsd: complex. Type> </xsd: element>

XML Schema に適合する例 <st: student number="abcd“> <st: family. Name> 安藤 </st: family. Name> <st:

XML Schema に適合する例 <st: student number="abcd“> <st: family. Name> 安藤 </st: family. Name> <st: given. Name>友晴</st: given. Name> </st: student>

XML Schema の例. . . <xsd: element ref="st: user. Name" />. . . <xsd:

XML Schema の例. . . <xsd: element ref="st: user. Name" />. . . <xsd: element name="user. Name"> <xsd: simple. Type> <xsd: restriction base="xsd: string"> <xsd: max. Length value="8" /> </xsd: restriction> </xsd: simple. Type> </xsd: element>

データの制限 <xsd: simple. Type> <xsd: restriction base="xsd: string"> <xsd: max. Length value="8" /> </xsd:

データの制限 <xsd: simple. Type> <xsd: restriction base="xsd: string"> <xsd: max. Length value="8" /> </xsd: restriction> </xsd: simple. Type> n string 型の最大長を8文字に制限する

XML Schema に適合する例 <st: student> <st: family. Name> 安藤 </st: family. Name> <st: given.

XML Schema に適合する例 <st: student> <st: family. Name> 安藤 </st: family. Name> <st: given. Name>友晴</st: given. Name> <st: user. Name>tomoharu</st: user. Name> </st: student>

XML Schema の例. . . <xsd: attribute ref="st: student. ID" />. . . <xsd:

XML Schema の例. . . <xsd: attribute ref="st: student. ID" />. . . <xsd: attribute name="student. ID"> <xsd: simple. Type> <xsd: restriction base="xsd: string"> <xsd: pattern value="d{2}-d{3}" /> </xsd: restriction> </xsd: simple. Type> </xsd: attribute>

正規表現を利用した データの制限 <xsd: simple. Type> <xsd: restriction base="xsd: string"> <xsd: pattern value="d{2}-d{3}" /> </xsd:

正規表現を利用した データの制限 <xsd: simple. Type> <xsd: restriction base="xsd: string"> <xsd: pattern value="d{2}-d{3}" /> </xsd: restriction> </xsd: simple. Type> n pattern 要素の value 属性に正規表現を 指定できる。

XML Schema に適合する例 <st: student. ID="00 -01 -001“> <st: family. Name>安藤</st: family. Name> <st:

XML Schema に適合する例 <st: student. ID="00 -01 -001“> <st: family. Name>安藤</st: family. Name> <st: given. Name>友晴</st: given. Name> <st: email> tomoharu@wakhok. ac. jp </st: email> <st: user. Name>tomoharu</st: user. Name> </st: student>

参考文献・URL n Extensible Markup Language (XML) 1. 0 (Third Edition) n n n http:

参考文献・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 の仕様書など。