...

View Full Version : Combing two Xpath queries



najeeb
11-12-2008, 06:49 AM
Hi all,

I'm trying to retrieve data from an xml file using xpath in PHP.

The following is the structure of the xml file:


<person>
<directory>
<directoryname>Public Utility Services</directoryname>
<personname>railwaystation</personname>
<portifolio/>
<constituency/>
<housename/>
<officeno/>
<residenceno/>
</directory>
<directory>
.....
.....
</directory>
.....
<person>


If I use,


$namedir = "Public Utility Services";
$xml->xpath('//directory[directoryname="'.$namedir.'"]/personname

I get all 'personname' under "Public Utility Services" element.

Whereas, when I use

$name ="s";
$xml->xpath('//directory/personname[starts-with(.,"'.$name.'")]


I get all 'personname' which starts with "s" ($name = "s").

I'd like to retrieve all 'personname' elements which satisfies both the conditions mentioned above. I tried with 'and' operator with no luck.

Thank you for any input.
Najeeb

oesxyl
11-12-2008, 07:16 AM
try this:


//directory[directoryname="'.$namedir.'" and personname[starts-with(.,"'.$name.'")]]/personname


regards

najeeb
11-12-2008, 07:25 AM
I got it working .......Thank you

oesxyl
11-12-2008, 07:30 AM
I got it working .......Thank you
you are welcome.

best regards



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum