How can i validate the text length of the element that has an attribute.
E.g:
<sport code="FB">Football</sport>
Now i need to restrict the possible values of the code attribute(like “FB”, “BB”, “TT”)
and also i need to restrict the possible values and length of the text(“Football”, “BasketBall”, “TableTennis”) and also the maximum length of these text(“Football”, “BasketBall”, “TableTennis”) can be 20.
I tried with
<complexType name="sport">
<simpleContent>
<extension base="string">
<attribute name="code" type="code" />
</extension>
</simpleContent>
</complexType>
<simpleType name="code">
<restriction base="string">
<enumeration value="FB" />
<enumeration value="BB" />
<enumeration value="TT" />
</restriction>
</simpleType>
But i cant validate the length of the text “Foolball” (also the possible values)
Can you please help about how to validate both the code and the text.
Thanks
I had this identical question, and was hopeful when I saw there was an accepted answer. However, that answer is exactly what I tried, but I was getting a schema invalid error. Apparently, you can’t restrict
simpleContentwithin acomplexType, only extend it. Additionally, you can’t have both an attribute andsimpleContentwithin acomplexType. Searching for examples in books around the office, I came up with a fix, which I adapted to this question in case someone else has this problem in the future: