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
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