Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6231445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:56:13+00:00 2026-05-24T09:56:13+00:00

How do I get the value of a node with XPath? Get all nodes

  • 0

How do I get the value of a node with XPath?

Get all nodes which have a price above 35

/bookstore/book[price>35.00]

But when I change the > to an = for equals, the query fails.
Please help. By the way I’m using php, but that shouldn’t matter as XPath is universal.

Here’s the php code and xml code I was using

$xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
 <bookstore>
 <book>
   <title lang=\"eng\">Harry Potter</title>
   <price>29.99</price>
 </book>
 <book>
   <title lang=\"eng\">Learning XML</title>
   <price>39.95</price>
 </book>
 </bookstore>"; $xml = new SimpleXMLElement($xml);

    $name = 'Shiny Red';
    $nodes = $xml->xpath(sprintf('/bookstore/book[price>35.00]', $name));
    if (!empty($nodes)) {
        printf('At least one building named "%s" found<hr/>', $name);
    echo "<textarea style=\"width: 400px; height: 300px;\">";print_r($nodes); echo "</textarea>";
    } else {
        printf('No building named "%s" found', $name);
    }    
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:56:14+00:00Added an answer on May 24, 2026 at 9:56 am
    //bookstore/book/price[. ='35.00']
    

    or

    //bookstore/book[price='35.00']
    

    The trick is in the quotes. Node values are text. You won’t match anything with ‘35.00’ however, but that is because your XML doesn’t contain books with that price. Matching ‘39.95’ will work (tested).

    $xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>
     <bookstore>
     <book>
       <title lang=\"eng\">Harry Potter</title>
       <price>29.99</price>
     </book>
     <book>
       <title lang=\"eng\">Learning XML</title>
       <price>39.95</price>
     </book>
     </bookstore>"; $xml = new SimpleXMLElement($xml);
    
        $name = 'Shiny Red';
        $nodes = $xml->xpath(sprintf('//bookstore/book/price[. = \'39.95\']', $name));
        if (!empty($nodes)) {
            printf('At least one building named "%s" found<hr/>', $name);
        echo "<textarea style=\"width: 400px; height: 300px;\">";print_r($nodes); echo "</textarea>";
        } else {
            printf('No building named "%s" found', $name);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How get node value with its children nodes? For example I have following node
I have dropdown menu..which is dynamic.. How can get value of the last item
I have a via with some jQuery function to get value from HTML element
For example i have this xml. I need to get value of parameter val
I'm trying to get a node-set from a xsl variable for calculating. But my
Hey I have a node <msg> which contains a message such as string1 string
I`m new to Xpath and got a problem. I want all nodes under a
I have some trouble with XPath. For some unknown reason the result I get
I have the following XML, I am trying to get the unique nodes based
I am having problems finding the proper XPATH syntax to get the nodes I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.