Reply to Re: XPath Query Exressions and Quote Characters

Your name:

Reply:


Posted by C Drozdowski on 03/16/05 23:48

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@telesuite.com (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.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация