ぽざうねっと

ホーム 連絡をする 同期する ( RSS 2.0 ) Login
投稿数  420  : 記事  0  : コメント  9718  : トラックバック  76

ニュース

さて、今年は何を漬けようか

書庫

日記カテゴリ

Accessory

Community

Private

下記のような XML インスタンスに対する Schema を考えます。
<root>
    <sub1>
        <child1>aaa</child1>
        <child2>bbb</child2>
        <child3>ccc</child3>
    </sub1>
    <sub2>
        <child1>aaa</child1>
        <child2>bbb</child2>
        <child3>ccc</child3>
        <child4>ddd</child4>
    </sub2>
</root>
まず、このような XML Schema ができあがりました。
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="root">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="sub1" type="sub1Type"/>
                <xsd:element name="sub2" type="sub2Type"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

    <xsd:complexType name="sub1Type">
        <xsd:sequence>
            <xsd:element name="child1" type="xsd:string"/>
            <xsd:element name="child2" type="xsd:string"/>
            <xsd:element name="child3" type="xsd:string"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="sub2Type">
        <xsd:sequence>
            <xsd:element name="child1" type="xsd:string"/>
            <xsd:element name="child2" type="xsd:string"/>
            <xsd:element name="child3" type="xsd:string"/>
            <xsd:element name="child4" type="xsd:string"/>
        </xsd:sequence>
</xsd:schema>
sub2Type と sub1Type は重複している部分がありますね。
こんな場合、sub2Type を sub1Type の拡張として定義できます。
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="root">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="sub1" type="sub1Type"/>
                <xsd:element name="sub2" type="sub2Type"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

    <xsd:complexType name="sub1Type">
        <xsd:sequence>
            <xsd:element name="child1" type="xsd:string"/>
            <xsd:element name="child2" type="xsd:string"/>
            <xsd:element name="child3" type="xsd:string"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="sub2Type">
        <xsd:complexContent>
            <xsd:extension base="sub1Type">
                <xsd:sequence>
                    <xsd:element name="child4" type="xsd:string"/>
                </xsd:sequence>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>
</xsd:schema>
こんな感じです。
ここで、XML インスタンス文書が下記のように変更されたとしましょう。
<root>
    <sub1>
        <child0>---</child0>
        <child1>aaa</child1>
        <child2>bbb</child2>
        <child3>ccc</child3>
    </sub1>
    <sub2>
        <child0>---</child0>
        <child1>aaa</child1>
        <child2>bbb</child2>
        <child3>ccc</child3>
        <child4>ddd</child4>
    </sub2>
</root>
すると XML Schema は下記のようになります。
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="root">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="sub1" type="sub1Type"/>
                <xsd:element name="sub2" type="sub2Type"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>

    <xsd:complexType name="sub1Type">
        <xsd:sequence>
            <xsd:element name="child0" type="xsd:string"/>
            <xsd:element name="child1" type="xsd:string"/>
            <xsd:element name="child2" type="xsd:string"/>
            <xsd:element name="child3" type="xsd:string"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="sub2Type">
        <xsd:complexContent>
            <xsd:extension base="sub1Type">
                <xsd:sequence>
                    <xsd:element name="child4" type="xsd:string"/>
                </xsd:sequence>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>
</xsd:schema>
ようするに、1 箇所変更するだけで対処できますよということです。
一番最初に示した Schema だと 2 箇所変更する必要があります。

xsd:sequence 以外にもxsd:all, xsd:choice などが使えますし、もちろん属性の追加もできます。
ただし、最後にしか追加することはできません。
投稿日時 : 2007年3月20日 0:39

コメント

# vfaYdeqXdSJX 2011/09/28 14:41 http://oemfinder.com
aQGJJ7 Received the letter. I agree to exchange the articles.

# RWMxQqtQsVTlrA 2011/10/18 17:26 http://www.best-software.net/vend-name/adobe
Comrade kill yourself.

# nlekWIGAwAD 2011/10/18 17:30 http://www.software-stock.com/brand/adobe
The material is on the five plus. But there is a minus! My internet speed 56kb/sek. The page was loading for about 40 seconds!...

# rRsgKweZwXFUO 2011/10/22 21:29 http://www.discountwatchstore.com/Bulova-Watches_c
Stupid article..!

# DewMbGriiPqoUd 2011/11/02 5:14 http://www.pharmaciecambier.com/
Well, actually, a lot of what you write is not quite true !... well, okay, it does not matter:D

# UnbSGArxAuI 2011/11/02 6:07 http://optclinic.com/
A unique note..!

# TTZwFpDgbMLNvq 2011/11/07 19:05 http://www.metalland.net/loans/
Yeah !... life is like riding a bicycle. You will not fall unless you stop pedaling!!...

# EEadAZkgSYxzGVghQQG 2011/11/07 19:08 http://aphrodisiaquesnaturel.com
Yeah? I read and I understand that I do not understand anything what it is about:D

# PtleVniwwvXEOIb 2011/11/07 19:50 http://www.farmaciaunica.com/
Hooray! the one who wrote is a cool guy..!

# OsvfUoiWQpRPXG 2011/11/08 6:27 http://papillomasfree.com
See it for the first time!!...

# JmaKfvtNwpoBzO 2011/11/12 22:10 http://optclinic.com/
Strange but true. Your resource is expensive. At least it could be sold for good money on its auction!...

# RYLietbPpYts 2011/11/13 18:32 http://sildenafil-citrate.net/
Hello! How do you feel about young composers?!...

# hVJDFCvjknazTfx 2011/11/15 3:38 http://www.pharmaciedelange.com/
Stupid article..!

# XaCjSVMqegiGX 2011/11/16 2:07 http://www.discountwatchstore.com/Michael-Kors_c_4
Yeah? I read and I understand that I do not understand anything what it is about:D

# ijBfheqWxK 2011/11/16 3:45 http://www.laurenslinens.com/
Current blog, fresh information, I read it from time to time!!...

# FUuPkOqRFKnmuyUQ 2011/11/16 20:36 http://www.solution-naturelle.com/
I serched through the internet and got here. What a wonderful invention of the mankind. With the help of the network you communicate, learn, read !... That helped us to get acquainted!...

Post Feedback

タイトル
名前
Url:
コメント: