SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    960
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    xpath predicate help again!

    Hai folks,

    I want to get the secondary people's first names under listing1.
    so the result would be Dorothy and Desmond.

    I just the below xpath predicate. but not working it seems.

    Note: i cant use [last()-1] here. coz there lot of listing like this. i just posted two listing only.

    Code:
    $result = $xml->xpath('//wp:listing[1]/wp:people/wp:person[wp:rank="secondary"]');


    Code:
    <wp:listings>
    -<wp:listing>
    --<wp:people>
    
    ---<wp:person wp:rank="primary">
    -----<wp:firstname>Harry</wp:firstname>
    ---</wp:person>
    
    ---<wp:person wp:rank="secondary">
    ----<wp:firstname>Dorothy</wp:firstname>
    ---</wp:person>
    
    ---<wp:person wp:rank="secondary">
    ----<wp:firstname>Desmond</wp:firstname>
    ---</wp:person>
    
    --</wp:people>
    -</wp:listing>
    
    -<wp:listing>
    --<wp:people>
    
    ---<wp:person wp:rank="primary">
    -----<wp:firstname>John</wp:firstname>
    ---</wp:person>
    
    ---<wp:person wp:rank="secondary">
    ----<wp:firstname>jancy</wp:firstname>
    ---</wp:person>
    
    ---<wp:person wp:rank="secondary">
    ----<wp:firstname>jenny</wp:firstname>
    ---</wp:person>
    
    --</wp:people>
    -</wp:listing>
    <wp:listings>

  2. #2
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    960
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks folks,
    problem has been solved.
    i should have called the predict another step further.

    Code:
    $result = $xml->xpath('//wp:listing[1]/wp:people/wp:person[@wp:rank="secondary"]/wp:firstname');


Bookmarks

Posting Permissions

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