Reputation: 86847
How can I assert an xpath match that contains single quotes within the string to be asserted?
This is my string with value '40' to be asserted.
I assumed to escape the single quote characters with \'
but that does not work.
matches( //faultstring[1]/text(), 'This is my string with value \'40\' to be asserted.' )
How is this done properly?
Upvotes: 2
Views: 1895
Reputation: 243519
My understanding of this question is that the problem is caused by the need to use nested quotes if the XPath expression is within an XML document.
If this is the case, one can use this XPath expression:
$yourString = "This is my string with value '40' to be asserted."
XSLT - based verification:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:copy-of select=
"/* = "This is my string with value '40' to be asserted.""/>
</xsl:template>
</xsl:stylesheet>
When this transformation is applied on the following XML document:
<t>This is my string with value '40' to be asserted.</t>
the XPath expression is evaluated and the result of this evaluation is copied to the output:
true
Upvotes: 1