Guest ulta Posted July 5, 2007 Share Posted July 5, 2007 ...<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). Link to comment Share on other sites More sharing options...
eight968 Posted July 7, 2007 Share Posted July 7, 2007 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? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.