Re: XPath Query Exressions and Quote Characters

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



It's just a coincidence that I used xml:id as part of my query expression. If I use following code method to build my expression:

$query = '//book/chapter[section="' . $section . '"]';

or say

$query = '//book/chapter[@title="' . $title . '"]';

I get an "Invalid Predicate..." error when either the $section or $title variable contains a double quote.

However, here's an example:

XML:


<?xml version="1.0" encoding="UTF-8"?> <table> <row> <mod_id>home</mod_id> <mod_access>1</mod_access> <mod_name>"Home"</mod_name> </row> </table>

XPath Expression:

$query = '//table/row[mod_name="' . $name . '"]';

Variable Assignment:

$name = utf_encode('"Home"');

Using the expression throws the "Invalid Predicate" Error.




On 2005-03-16 12:06:24 -0500, jason.barnett@xxxxxxxxxxxxx (Jason Barnett) said:


C Drozdowski wrote: ...
$query = '//book/chapter' . '[@xml:id="' . $id . '"]';

First of all check the XPath documentation:

http://www.w3.org/TR/xpath
http://www.w3.org/TR/xpath#path-abbrev

AFAIK your expression above is the way to build this query.  Give us a
link to the XML doc if you want us to take a look at that specific doc.
 Also make sure you referenced the correct DTD.  And (just to be sure)
try to validate you document against the DTD.


Given this expression, if $id contains one or more single quotes, an error is thrown.

$query = "//book/chapter[@xml:id='$id']";

I need to be able to build an exression that contains either double or
single quotes in the search regarding of how I programatically build the
expression.


A couple of things that may be in play here...

- First of all I recall there was a specific bug with xml:id, although I
can't recall off the top of my head what it was...
- Secondly the XPath querying interface in PHP will only return simple
data at this point.  In fact, I think it will only return strings.

http://www.w3.org/TR/xpath#attribute-nodes

But if your ID is simple data (integer / string), I can't imagine it
would be a problem for XPath to return it.

-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux