开发者

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 &amp; instead of the character &.


Try using an entity reference:

  <xs:simpleType name="values">
    <xs:restriction base="xs:string">
      <xs:enumeration value="IN &amp; 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 &#38; 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.

  1. What's the error.
  2. Have you tried replacing & with

    &amp; 
    

    Since it's an escape entity?

Cheers.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜