Jump to content
Sign in to follow this  
Guest ulta

xs:choice question

Recommended Posts

Guest ulta
...<xs:choice><xs:element name="Score" type="scoresRequiringComment" /><xs:element name="Score" type="scoresRequiringValidThrough" /><xs:element name="Score" type="otherScores" /></xs:choice>...

<xs:complexType name="scoresRequiringComment"><xs:sequence><xs:element name="score" nillable="false"><xs:simpleType><xs:restriction base="xs:string"><xs:enumeration value="B" /><xs:enumeration value="C" /><xs:enumeration value="D" /></xs:restriction></xs:simpleType></xs:element><xs:element name="validThrough" type="xs:date" nillable="true" /><xs:element name="comment" type="xs:string" nillable="false" /></xs:sequence></xs:complexType>

<xs:complexType name="scoresRequiringValidThrough"><xs:sequence><xs:element name="score" nillable="false"><xs:simpleType><xs:restriction base="xs:string"><xs:enumeration value="Delay" /></xs:restriction></xs:simpleType></xs:element><xs:element name="validThrough" type="xs:date" nillable="false" /><xs:element name="comment" type="xs:string" nillable="false" /></xs:sequence></xs:complexType>

<xs:complexType name="otherScores"><xs:sequence><xs:element name="score" nillable="false"><xs:simpleType><xs:restriction base="xs:string"><xs:enumeration value="A" /></xs:restriction></xs:simpleType></xs:element><xs:element name="validThrough" type="xs:date" nillable="true" /><xs:element name="comment" type="xs:string" nillable="true" /></xs:sequence></xs:complexType>

Basically, If the score is of value A, a comment and a date are not required but not prohibited. If you have a "Delay", you haev to have a date and a comment. If you have B,C, or D, you have to have a comment, but you don't have to have a date. I get a warning in Visual Studios 2005 about the first code block being ambiguous. Am I doing this correctly, and if I am not, how do I accomplish this (Short of just naming each thing in the choice block a different name (Score1, Score2, Score3), I'd like to avoid that, because I need to parse the XML later and that will bring up complications).

Share this post


Link to post
Share on other sites

You have a couple of options. But yes, the ambiguity is from the multiple items of the name name. What you could do is define score like this:<xs:element name="Score" type="xs:abstract"><xs:element name="Score1"> <xs:complexType> <xs:complexContent> <xs:extension base="Score">...Then you could see<Score1> ...or<Score xsi:type="Score1">However, this aside, it's generally easier to parse xml if you know exactly what type it is from the name. What are you using to parse it?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...