Limit content of a tag with Schema

Discussion in 'XML' started by jiaqi.guo@gmail.com, Dec 8, 2004.

  1. Guest

    I want to limit the content of a tag to be a string or another tag. How
    can I do it?
    <mytag att1="abc">Hello World</mytag>
    or
    <mytag att1="abc"><tag1>...</tag1></mytag>
    or
    <mytag att1="abc"><tag2>...</tag2></mytag>

    Only pure text , one <tag1> OR one <tag2> is allowed in <mytag>
    How should I define <mytag> in schema.


    Thanks in advance
    Jiaqi
     
    , Dec 8, 2004
    #1
    1. Advertising

  2. Hi Jiaqi,

    You need to use a mixed model to allow both text and other elements within
    <mytag> element. However, with a mixed model you cannot constrain the
    position of the text nodes. So if you use it, it will allow text OR tag1 OR
    tag2 OR text and tag1 OR text and tag2. Also note that in the last two
    cases the text can appear before, after, or both before and after tag1 or
    tag2 elements.

    Here's an example:

    <xs:complexType name="mytag" mixed="true">
    <xs:choice minOccurs="0" maxOccurs="1">
    <xs:element name="tag1" type="tag1" />
    <xs:element name="tag2" type="tag2" />
    </xs:choice>
    </xs:complexType>
    <xs:element name="mytag" type="mytag" />

    --
    Stan Kitsis
    Program Manager, XML Technologies
    Microsoft Corporation

    This posting is provided "AS IS" with no warranties, and confers no rights.


    <> wrote in message
    news:...
    >I want to limit the content of a tag to be a string or another tag. How
    > can I do it?
    > <mytag att1="abc">Hello World</mytag>
    > or
    > <mytag att1="abc"><tag1>...</tag1></mytag>
    > or
    > <mytag att1="abc"><tag2>...</tag2></mytag>
    >
    > Only pure text , one <tag1> OR one <tag2> is allowed in <mytag>
    > How should I define <mytag> in schema.
    >
    >
    > Thanks in advance
    > Jiaqi
    >
     
    Stan Kitsis [MSFT], Dec 15, 2004
    #2
    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.

Share This Page