Search code examples
xsdassertxsd-1.1single-quotes

XSD 1.1 assert test containing single quote


Anybody got an idea why the following won't work? The xsd is validated with 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>

The error hits when i use the single quote &apos; entity...

Thanks


Solution

  • Your problem is related to XPath string literals, as XSD 1.1 uses XPath 2.0 you can escape an apostrophe or quotes inside a string literal by writing the delimiter two times, so you can use:

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

    For more info you can use 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.