newbie: how to create this kind of schema

Discussion in 'XML' started by mcha226@gmail.com, Dec 9, 2005.

  1. Guest

    Hi All:
    In my XML document, sometimes I have:

    <a>xxxxxxxx</a>

    and sometimes I have

    <a><text>xxxxx xxxxx</text></a>

    which can distinguish a long text and a ordinary string.

    I am trying to come up with a general schema which will think both are
    valid.
    I tried to creat a type which can be used for this by using xs:choice.
    However I am not really successful as my schema cannot pass the schema
    validator.
    Can anyone tell me how I can do that? Thanks.
    , Dec 9, 2005
    #1
    1. Advertising

  2. writes:

    > In my XML document, sometimes I have:
    >
    > <a>xxxxxxxx</a>
    >
    > and sometimes I have
    >
    > <a><text>xxxxx xxxxx</text></a>


    <xs:element name="a">
    <xs:complexType mixed="true">
    <xs:sequence>
    <xs:element name="text"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>

    Not perfect, as will allow e.g. <a>x<text>xxx xx</text>x</a> as well
    as what you want, but closest you can get with W3C XML Schema.

    ht
    --
    Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
    Half-time member of W3C Team
    2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
    Fax: (44) 131 650-4587, e-mail:
    URL: http://www.ltg.ed.ac.uk/~ht/
    [mail really from me _always_ has this .sig -- mail without it is forged spam]
    Henry S. Thompson, Dec 9, 2005
    #2
    1. Advertising

  3. The following blog posts describes different ways of achieving this:
    http://blogs.msdn.com/xmlteam/archive/2004/12/30/344573.aspx

    --
    Stan Kitsis
    Program Manager, XML Technologies
    Microsoft Corporation

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at
    http://www.microsoft.com/info/cpyright.htm

    <> wrote in message
    news:...
    > Hi All:
    > In my XML document, sometimes I have:
    >
    > <a>xxxxxxxx</a>
    >
    > and sometimes I have
    >
    > <a><text>xxxxx xxxxx</text></a>
    >
    > which can distinguish a long text and a ordinary string.
    >
    > I am trying to come up with a general schema which will think both are
    > valid.
    > I tried to creat a type which can be used for this by using xs:choice.
    > However I am not really successful as my schema cannot pass the schema
    > validator.
    > Can anyone tell me how I can do that? Thanks.
    >
    Stan Kitsis [MSFT], Dec 9, 2005
    #3
  4. Guest

    Hehe, I am a newbie, that's why I just found out that the following
    schema will not validate.
    ...
    <xs:choice>
    <xs:group ref="a"/>
    <xs:group ref="b"/>
    </xs:choice>
    ...
    ...
    <xs:group name="a">
    <xs:sequence>
    <xs:element ref="type"/>
    <xs:element ref="gender"/>
    </xs:sequence>
    </xs:group>
    <xs:group name="b">
    <xs:sequence>
    <xs:element ref="type"/>
    <xs:element ref="street"/>
    </xs:sequence>
    </xs:group>
    ...
    ...

    So I can't really have 2 groups having the same element when I am
    having a choice bewteen these 2 groups. Is this supposed to be the way
    it is, and is there a way around it?
    Cheers
    Mark
    , Dec 13, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Tucker
    Replies:
    0
    Views:
    553
    Andrew Tucker
    Aug 23, 2003
  2. ali
    Replies:
    2
    Views:
    375
    Ross Bamford
    May 11, 2005
  3. Albretch Mueller

    Kind of tamplating XML schema

    Albretch Mueller, May 19, 2005, in forum: Java
    Replies:
    1
    Views:
    349
    John C. Bollinger
    May 19, 2005
  4. Markus
    Replies:
    1
    Views:
    1,491
    Markus
    Nov 23, 2005
  5. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,164
    Stanimir Stamenkov
    Apr 25, 2005
Loading...

Share This Page