views:

152

answers:

3
+1  Q: 

XSD validation

Can anybody help me to build an XSD file to validate XMLs like these:

[test] [a/] [b/] [a/] [b/] [/test]

[test] [a/] [a/] [b/] [/test]

Basically, I can have any number of and/ or nodes, without any other rule (can't use ).

Thanks.

A: 

If you paste the sample XML, we can help you better. However, Microsoft has an XSD code generator that generates an XSD based on an XML file that you pass in as an argument.

George Stocker
A: 

In my initial post you have to replace [ ] with < >

So the XML files used as example would be:

<test>
<a/>
<b/>
<a/>
<b/>
</test>

Or second XML:

<test>
<a/>
<a/>
<b/>
</test>

I already tried XSD generator from XMLPad but it builds xs:sequence which require exact order of the nodes as they are in one ot the other example.

Can anybody give me an example of XSD file which validates BOTH XMLs?

Thanks.

Use the example I gave you, generate both XSDs, and then dissect them to find the union of the product.
George Stocker
+1  A: 

It isn't going to very fast if you have a lot of a or b nodes but this validates against what you've described.

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
  <xs:element name="test">
    <xs:complexType>
      <xs:sequence>
        <xs:choice maxOccurs="unbounded">
          <xs:element name="a"/>
          <xs:element name="b"/>
        </xs:choice>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>
MotoWilliams