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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:45:13+00:00 2026-05-22T23:45:13+00:00

I want to get data from an XPath query: Element location = (Element) doc.query(//location[location_name=’+

  • 0

I want to get data from an XPath query:

Element location = (Element) doc.query("//location[location_name='"+ locationName +"']/*").get(0).getDocument().getRootElement();
System.out.println(location.toXML());

Element loc = location.getFirstChildElement("location");
System.out.println(loc.getFirstChildElement("location_name").getValue());

However, no matter what I choose, I always get 1 node (because of .get(0)). I don’t know how to select the node which was selected by query.

I found that I should cast the node to Element, (XOM getting attribute from Node?) but the link only shows how to select the first node.

  • 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-22T23:45:14+00:00Added an answer on May 22, 2026 at 11:45 pm

    Call getParent() on the first element in the result:

    Builder parse = new Builder();
    Document xml = parse.build("/var/www/JAVA/toForum.xml");
    
    System.out.println(xml.query("//location[@id=83]/*").get(0).getParent().toXML());
    

    Produces the following output:

    <location id="83">
      <location_name>name</location_name>
      <company_name>company a</company_name>
      <machines>
        <machine id="12">A</machine>
        <machine id="312">B</machine>
      </machines>
    </location>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using http://lite.facebook.com And i want to get some data from my account.
I have one problem , I want to get some data from XML file
What I want to do is get the data from two different tables (table1
I want to pull in data using a XML::XPath parser from a XML DB
I want to get data from this page: http://www.canadapost.ca/cpotools/apps/track/personal/findByTrackNumber?trackingNumber=0656887000494793 But that page forwards to:
I want to get data from a database of my site. In the setting
I want to get data from Postgres. There is a column in type timestamp
I want to get data from a text file to a listview. A sample
I want to get data from my data access layer into my business layer,
I want to get data from SharePoint List using CAML and filtered by Title

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.