How can I do this in a Schema?

Questions about XML that are not covered by the other forums should go here.
Douha
Posts: 17
Joined: Fri Aug 19, 2005 6:02 pm

How can I do this in a Schema?

Post by Douha »

Hi all,

I have a question about how to create a schema that will validate this format.

I have a file that used to have a format like this.

element type 1
element type 2
element type 2
element type 2
element type 3
element type 3
element type 3
element type 3

It has been changed to this format.


element type 1
element type 2
element type 3
element type 3
element type 2
element type 3
element type 3
element type 2
element type 3

I have a schema that works for the former format. I haven't been able to figure out how to get one to validate the new format.

Could someone please point me in a direction to help figure it out?

Thanks much,

Doug
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi Doug,

I'm not sure what you want the schema model to cover, if you want for instance element type 1 followed by any of element type 2 or 3 aany numner of times then you can encode that as

Code: Select all


<xs:sequence>
<xs:element name="element1" type="type1">
<xs:choice maxOccurs="unbounded">
<xs:element name="element2" type="type2">
<xs:element name="element3" type="type3">
</xs:choice>
</xs:sequence>
If that is not what you want then please provide more details.

Best Regards,
George
Douha
Posts: 17
Joined: Fri Aug 19, 2005 6:02 pm

Post by Douha »

Thanks George,

What I am trying to accomplish is this.

For every element 1 there will be at least 1 element 2 that will immediatly follow element 1.
For every element 2 there will be at least 1 element 3 that will immediately follow element 2.

So the following would be what I am trying to model.

E1
E2
E3
E3
E3
E2
E3
E2
E3
E3

The following would be incorrect and cause an error.

E1
E3
E2

E1
E2
E2
E3
E3

or

E2
E3
E1

Does this make sense?

Thanks,

Doug
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post by george »

Hi Doug,

That seems something like:

Code: Select all


      <xs:sequence>
<xs:element name="E1"/>
<xs:sequence maxOccurs="unbounded">
<xs:element name="E2"/>
<xs:sequence maxOccurs="unbounded">
<xs:element name="E3"/>
</xs:sequence>
</xs:sequence>
</xs:sequence>
Best Regards,
George
Post Reply