0
votes

I have a large set of similar programs that return xml roughly like so:

<result>
  <query>
  </query>
  <transaction>
   <revenue>
     ...
   </revenue>
  </transaction>
</result>

The query element always has the same structure. The revenue element on the other hand has one of six structure depending on the specific program. While they all contain similar data, due to the underlying system (which I can't fix atm) each variation is completely different. It's not just a case of a few additional attributes for each, they are completely different.

I'm trying to make an XSD to validate the XML returned by any of the programs. I have an XSD for each variation of the revenue element but I'd like to combine them into one that will validate any.

I've tried using:

<xs:choice>
<xs:element name="revenue">
  #variation
</xs:element>
<xs:element name="revenue">
  #Another variation
</xs:element>
<xs:element name="revenue">
  #Another variation
</xs:element">
</xs:choice>

But XSD doesn't like elements with the same names. Is there a way to work around this or otherwise achieve what I'm trying to do?

1

1 Answers

0
votes

It needs to be more like this:

<xs:element name="revenue">
  <xs:complexType>
    <xs:choice>
    #variation
    #Another variation
    #Another variation
    </xs:choice>
  </xs:complexType>
</xs:element>

But it's still not easy, because of UPA, and because you might want the attribute to vary as well as the content model. So the details depend on what the variations look like.

It would be easier if you used different element names for the different kinds of revenue, since in XSD by default the validation rules are a function of the element name.