schema nested simpletype

S

sk

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>
 
P

Priscilla Walmsley

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top