CDATA to ignore & in XSD
I need the xml parser/validator to ignore the presense of &
开发者_StackOverflow中文版How do I accomplish it by using CDATA in xsd.
This is snippet of xsd:
<xs:simpleType name="values">
<xs:restriction base="xs:string">
<xs:enumeration value="IN & OUT"/>
<xs:enumeration value="XYZ"/>
</xs:restriction>
</xs:simpleType>
I tried using CDATA as follows but in vain as I get xsd validation error:
<xs:simpleType name="values">
<xs:restriction base="xs:string">
<xs:enumeration value="IN <![CDATA[&]]> OUT"/>
<xs:enumeration value="XYZ"/>
</xs:restriction>
</xs:simpleType>
Any help is appreciated.
Thansk in advance.
I believe you can use the entity reference &
instead of the character &
.
Try using an entity reference:
<xs:simpleType name="values">
<xs:restriction base="xs:string">
<xs:enumeration value="IN & OUT"/>
<xs:enumeration value="XYZ"/>
</xs:restriction>
</xs:simpleType>
or a decimal reference:
<xs:simpleType name="values">
<xs:restriction base="xs:string">
<xs:enumeration value="IN & OUT"/>
<xs:enumeration value="XYZ"/>
</xs:restriction>
</xs:simpleType>
Hmm. I find it interesting how that line in the second snippet is actually black instead of the properly coloured elements.
May I ask what the validation error is? It may help in pinpointing what is exactly wrong with that line of code. It may be true that the parser will ignore the & sign, but have you tried replacing the & with '&' ? The thing is, I have a feeling you're setting the enumeration value to
"IN <![CDATA[&]]> OUT"/>
Which would... obviously not pass the validation. Either that or the parser completely passes over that line and only takes in XYZ as an enum value.
- What's the error.
Have you tried replacing & with
&
Since it's an escape entity?
Cheers.
精彩评论