XSD 1.1 断言测试包含单引号

XSD 1.1 assert test containing single quote

有人知道为什么以下方法不起作用吗? 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; 实体时出现错误...

谢谢

您的问题与 XPath 字符串文字有关,因为 XSD 1.1 使用 XPath 2.0 您可以通过两次写入定界符来转义字符串文字中的撇号或引号,因此您可以使用:

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

有关更多信息,您可以使用 XPath 2.0 specs, section Literals:

If the literal is delimited by apostrophes, two adjacent apostrophes within the literal are interpreted as a single apostrophe. Similarly, if the literal is delimited by quotation marks, two adjacent quotation marks within the literal are interpreted as one quotation mark.