xml - XSD for simplecontent with attribute and text -


How can I validate the length of the text of that element in which there is an attribute Example:

  & lt; Game code = "FB" & gt; Football & lt; / Sport & gt;   

Now I need to restrict the potential values ​​of code attributes (like "FB", "BB", "TT") and I need to restrict its potential values ​​and length The text ("football", "basketball", "table tennis") and the maximum length of these lessons ("football", "basketball", "tablettini") can be 20.

I tried

  & lt; Complex type name = "sports" & gt; & Lt; SimpleContent & gt; & Lt; Extension base = "string" & gt; & Lt; Attribute name = "code" type = "code" /> & Lt; / Extension & gt; & Lt; / SimpleContent & gt; & Lt; / ComplexType & gt; & Lt; Simple type name = "code" & gt; & Lt; Restriction base = "string" & gt; & Lt; Enumeration value = "FB" /> & Lt; Calculation value = "bb" /> & Lt; Enumeration value = "TT" /> & Lt; / Ban & gt; & Lt; / SimpleType & gt;   

But I can not validate the length of "flowerball" text (possibly even possible values) Can you please help validate both code and text thanks

I had this same question, and when I saw that there was an approved answer, I was hoping. However, this answer really did whatever I tried, but I was getting a schema invalid error. Obviously, you can not limit the simple content within a complex type, only expand it. In addition, you can not do both a feature and simple content within a complex type. Looking for examples of books around the office, I came with a fix, which I have optimized according to this question, if someone has this problem in the future:

  & Lt ;? Xml version = "1.0" encoding = "ISO-8859-1"? & Gt; & Lt; Xsd: schema xmlns: xsd = "http://www.w3.org/2001/XMLSchema" xmlns: sp = "http://www.ckhrysze.net/sports/1.0" targetNamespace = "http: // www. Ckhrysze.net/sports/1.0 "& gt; & Lt; Xsd: element name = "sports" & gt; & Lt; XSD: complexType & gt; & Lt; XSD: Sequence & gt; & Lt; Xsd: element name = "game" type = "sp: sport type" minOccurs = "1" maxOccurs = "unbounded" /> & Lt; / XSD: Sequence & gt; & Lt; / XSD: complexType & gt; & Lt; / XSD: element & gt; & Lt; Xsd: complex type name = "sports type" & gt; & Lt; XSD: simpleContent & gt; & Lt; Xsd: extension base = "sp: sports animation" & gt; & Lt; Xsd: attribute name = "code" type = "sp: codeEnumeration" /> & Lt; / XSD: Expansion & gt; & Lt; / XSD: simpleContent & gt; & Lt; / XSD: complexType & gt; & Lt; Xsd: Simple Type Name = "Sport Animation" & gt; & Lt; Xsd: ban base = "xsd: string" & gt; & Lt; Xsd: calculation value = "football" /> & Lt; Xsd: Calculation value = "basketball" /> & Lt; / XSD: Ban & gt; & Lt; / XSD: simpleType & gt; & Lt; Xsd: Simple Type Name = "Code Animation" & gt; & Lt; Xsd: ban base = "xsd: string" & gt; & Lt; Xsd: calculation value = "fb" /> & lt; Xsd: calculation value = "bb" /> & Lt; / XSD: Ban & gt; & Lt; / XSD: simpleType & gt; & Lt; / XSD: Schema & gt;    

Comments