XSD 1.1断言测试包含单引号

时间:2015-08-28 13:06:22

标签: xsd assert xsd-1.1 single-quotes

有人知道为什么以下不起作用? xsd通过Xerces验证

<xs:element name="myElement">
  <xs:complexType>
    <xs:complexContent>
      <xs:extension base="myElementType">
        <xs:assert test="firstname = 'George' and lastName = 'Mc&apos;Falrland'" />
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
</xs:element>

当我使用单引号&apos;实体...

时,错误就会出现

由于

1 个答案:

答案 0 :(得分:2)

你的问题与XPath字符串文字有关,因为XSD 1.1使用XPath 2.0你可以通过写分隔符两次来转义字符串文字中的撇号或引号,这样你就可以使用:

<xs:assert test="firstname = 'George' and lastName = 'Mc''Falrland'" />

有关详情,请使用XPath 2.0 specs, section Literals

  

如果文字由撇号分隔,则为两个相邻的撇号   在文字内被解释为单个撇号。同样的,   如果文字用引号分隔,则两个相邻的引号   文字中的标记被解释为一个引号。