Help: DOMXPath->Query, quotes and apostrophes



I seem to be hitting a wall here. I have the need to run an XPath query
on strings that may contain quotes, apostrophes or both. Going through
google turned up some interesting information, but nothing that solved
my issue.

An example of what I am trying to do is as follows:

$query = '\'foo"bar';
$xpath->query('/node[@name="'.$query.'"]')->item(0);

This produces these warnings and errors:

Warning: DOMXPath::query() [function.DOMXPath-query]: Invalid predicate
Warning: DOMXPath::query() [function.DOMXPath-query]: Invalid expression
Fatal error: Call to a member function item() on a non-object

I've tried to escape the characters in the query, but that seems to be
illegal for XPath from what I've read. I've tried turning the quotes
into " and apostrophes into ' but it appears that XPath
requires that the data be unencoded to work.

I've seen reference to using XSLT to set XPath variables instead, but I
don't understand how to do implement this.

I would really appreciate any examples on what people have done to get
around this issue, if any one has at all.

Regards,

Adam.

--
Adam Randall <adam@xxxxxxxxxxxxxxxxxxxx>
(206) 285-8080
100 West Harrison
North Tower, Suite 300
Seattle, WA
98119

"Engineers like to solve problems. If there are no problems handily
available, they will create their own problems." - Dilbert
.



Relevant Pages

  • Re: Passing xpath to a template
    ... In the end I resorted to a complete custom Xsl file and abandoned the mapper ... when I run a value-of statement on the xpath parameter I ... turns out to be the double quotes. ...
    (microsoft.public.biztalk.general)
  • Passing xpath to a template
    ... I ran into a bit of a piccle with the mapper. ... when I run a value-of statement on the xpath parameter I ... out to be the double quotes. ...
    (microsoft.public.biztalk.general)
  • Re: tdom parser problems with xmlns keyword
    ... Your XPath query is without XML namespaces, ... This is one of the ugliest things about using XPath: ...
    (comp.lang.tcl)
  • Re: XPath Question
    ... The two queries I posted worked for me, using XPath Xpress (downloaded off ... This type of XPath query can be done only for ... > 2) All tblItem nodes that have a Category of Miscellaneous (i.e., ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: tdom parser problems with xmlns keyword
    ... Your XPath query is without XML namespaces, ... way to put the mapping of prefixes to URLs in the query itself. ...
    (comp.lang.tcl)