schema nested simpletype

Discussion in 'XML' started by sk, Jun 13, 2006.

  1. sk

    sk Guest

    How can I validate the element within the a simgle element?
    I tried to make a schema like the following, but seems the schema
    is not right.

    xml doc
    <id0001>
    <id0002>hello</id0002>
    </id0001>

    schema i am trying to make
    <xs:element name="id0001">
    <xs:simpleType>
    <xs:sequence>
    <xs:element name="id0002">
    <xs:simpleType>
    <xs:restriction base="xs:string"/>
    </xs:simpleType>
    </xs:element>
    </xs:sequence>
    </xs:simpleType>
    </xs:element>
    </xs:schema>
     
    sk, Jun 13, 2006
    #1
    1. Advertising

  2. Hi,

    Because id0001 has children, it needs to have a complex type rather than
    a simple type. So:

    <xs:element name="id0001">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="id0002">
    <xs:simpleType>
    <xs:restriction base="xs:string"/>
    </xs:simpleType>
    </xs:element>
    </xs:sequence>
    </xs:complexType>
    </xs:element>

    Since id0002 is just a string, you could also do:

    <xs:element name="id0001">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="id0002" type="xs:string"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>

    Hope that helps,
    Priscilla

    ----------------------------------
    Priscilla Walmsley
    Author, Definitive XML Schema
    XQuery
    http://www.datypic.com
    ----------------------------------

    *** Sent via Developersdex http://www.developersdex.com ***
     
    Priscilla Walmsley, Jun 14, 2006
    #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.
Similar Threads
  1. Replies:
    0
    Views:
    445
  2. JamesG
    Replies:
    0
    Views:
    362
    JamesG
    Apr 19, 2007
  3. JamesG
    Replies:
    2
    Views:
    396
    JamesG
    Apr 21, 2007
  4. Anil Mamede
    Replies:
    2
    Views:
    426
    Anil Mamede
    Apr 6, 2008
  5. kanpeter
    Replies:
    0
    Views:
    1,336
    kanpeter
    Oct 26, 2010
Loading...

Share This Page