[PHP] Re: XPath Query Exressions and Quote Characters

2005-03-16 Thread Jason Barnett
C Drozdowski wrote:
...
 $query = '//book/chapter' . '[EMAIL PROTECTED]: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/[EMAIL PROTECTED]: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.

--
Teach a man to fish...

NEW? | http://www.catb.org/~esr/faqs/smart-questions.html
STFA | http://marc.theaimsgroup.com/?l=php-generalw=2
STFM | http://php.net/manual/en/index.php
STFW | http://www.google.com/search?q=php
LAZY |
http://mycroft.mozdev.org/download.html?name=PHPsubmitform=Find+search+plugins


signature.asc
Description: OpenPGP digital signature


[PHP] Re: XPath Query Exressions and Quote Characters

2005-03-16 Thread C Drozdowski
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/[EMAIL PROTECTED]' . $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_idhome/mod_id
   mod_access1/mod_access
   mod_nameHome/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, [EMAIL PROTECTED] (Jason Barnett) said:
C Drozdowski wrote:
...
$query = '//book/chapter' . '[EMAIL PROTECTED]: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/[EMAIL PROTECTED]: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