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 9188001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:54:36+00:00 2026-06-17T19:54:36+00:00

This is my XML <root> <entry id=1> <value name=ID>11</value> <value name=ENABLE>0</value> <value name=NAME>USER1</value> </entry>

  • 0

This is my XML

<root>
   <entry id="1">
      <value name="ID">11</value>
      <value name="ENABLE">0</value>
      <value name="NAME">USER1</value>
   </entry>
   <entry id="2">
      <value name="ID">11</value>
      <value name="ENABLE">0</value>
      <value name="NAME">USER2</value>
   </entry>
   <entry id="3">
      <value name="ID">12</value>
      <value name="ENABLE">0</value>
      <value name="NAME">USER1</value>
   </entry>
</root>

I need an XPath query to retrieve all the names whose id is 11.

I tried:

String xpath = "/root/entry/value[@name=ID/text()='11']/value[@name='NAME']";
String xpath = "/root/entry/value[@name=ID/text()='11']/NAME";

Can someone tell me what is wrong in my query?

EDIT:

Expected Output:

USER1
USER2

both these have ID = 11

  • 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-06-17T19:54:37+00:00Added an answer on June 17, 2026 at 7:54 pm

    This would be the correct path:

    /root/entry[value[@name = 'ID'] = 11]/value[@name = 'NAME']
    

    To retrieve a list of nodes, you need to use the version of xPath.evaluate() that takes a returnType parameter:

    InputSource document = new InputSource(new FileInputStream("user1.xml"));
    String xpath = "/root/entry[value[@name = 'ID'] = 11]/value[@name = 'NAME']";
    NodeSet result = (NodeSet)xPath.evaluate(xpath, document, XPathConstants.NODESET); 
    for(int index = 0; index < result.getLength(); index ++) {      
        Node node = result.item(index);
        String name = node.getNodeValue();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've a XML structure like this: <root> <element> <name>Foo</name> <subelement> <key>1.1</key> <value>Lorem ipsum</value> </subelement>
I have this XML: <root> <data name=lnkViewResultResource1.Text xml:space=preserve> <value>bekijk de resultaten</value> </data> <data name=lnkVoteResource1.Text
This is the xml data I need to generate xslt from. <root> <entry id=1>
given this xml: <root> <list> <!-- foo's comment --> <item name=foo /> <item name=bar
I have this XML code: <root> <node> </first_child> </second_child> </third_child> </node> </root> I need
All, I have the below sample XML: <Root> <Sample1>Sample1</Sample1> <Sample2>Sample2</Sample2> <Run> <Entry> <Level1A>Test1</Level1A> <Level1B>Test2</Level1B>
My input XML consists of the following, <root> <entry> <type>U</type> <value>111</value> </entry> <entry> <type>X</type>
I have a RelativeLayout with one child as <include another.xml> like this root.xml :
I've this xml <root> <node1> <node2>xxx</node2> </node1> ... <node1> <node2>yyy ABC yyy</node2> </node1> ...
I have this XML at http://localhost/file.xml : <?xml version=1.0 encoding=utf-8?> <val:Root xmlns:val=http://www.hw-group.com/XMLSchema/ste/values.xsd> <Agent> <Version>2.0.3</Version>

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.