Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Sep 2007
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Combing two Xpath queries

    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:
    Code:
    <person>
      <directory>
         <directoryname>Public Utility Services</directoryname>
         <personname>railwaystation</personname>
         <portifolio/>
         <constituency/>
         <housename/>
         <officeno/>
         <residenceno/>
      </directory>
      <directory>
    .....
    .....
      </directory>
    .....
    <person>
    If I use,
    PHP Code:
    $namedir "Public Utility Services";
    $xml->xpath('//directory[directoryname="'.$namedir."]/personname 
    I get all 'personname' under "Public Utility Services" element.

    Whereas, when I use
    PHP Code:
    $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

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    try this:
    Code:
    //directory[directoryname="'.$namedir.'" and personname[starts-with(.,"'.$name.'")]]/personname
    regards

  • Users who have thanked oesxyl for this post:

    najeeb (11-12-2008)

  • #3
    New to the CF scene
    Join Date
    Sep 2007
    Posts
    7
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I got it working .......Thank you

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by najeeb View Post
    I got it working .......Thank you
    you are welcome.

    best regards


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •