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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:18:18+00:00 2026-06-08T19:18:18+00:00

Using XPath. I have this doc: <?xml version=1.0?> <root> <items> <item1> <tag1>1</tag1> <tag2>DFGGFDGF</tag2> <tag3>3</tag3>

  • 0

Using XPath.

I have this doc:

<?xml version="1.0"?>
<root>
  <items>
    <item1>
      <tag1>1</tag1>
      <tag2>DFGGFDGF</tag2> 
      <tag3>3</tag3>
    </item1>

    <item2>
      <tag1>DFGD</tag1>
      <tag2>SDFSDFFSD</tag2>    
      <tag3>SDFSFDFS</tag3>
    </item2>
  </items>
</root>

I want to get the tags names of the item1 element.

Now i use this to get the tags value:

XPathExpression expr = xpath.compile("//"+ node_name +"/*/text()");
Object result = expr.evaluate(doc, XPathConstants.NODESET);
NodeList nodes = (NodeList) result;
for (int i = 0; i < nodes.getLength(); i++) {
  System.out.println(nodes.item(i).getNodeValue()); 
}

How do i get the tags names: tag1, tag2, tag3?

  • 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-08T19:18:21+00:00Added an answer on June 8, 2026 at 7:18 pm

    First of all, don’t use text() at the end of your XQuery. You need the nodes themselves. Second, don’t take the node value, you need the node name instead.

    XPathExpression expr = xpath.compile("//"+ node_name +"/*");
    Object result = expr.evaluate(doc, XPathConstants.NODESET);
    NodeList nodes = (NodeList) result;
    for (int i = 0; i < nodes.getLength(); i++) {
      System.out.println(nodes.item(i).getNodeName()); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an xml document like this: <?xml version=1.0 encoding=UTF-8?> <foo:root xmlns:foo=http://abc.com# xmlns:bar=http://def.com xmlns:ex=http://ex.com>
I have a process that parses an XML file using JDOM and xpath to
Lets assume we have this xml: <?xml version=1.0 encoding=UTF-8?> <tns:RegistryResponse status=urn:oasis:names:tc:ebxml-regrep:ResponseStatusType:Failure xmlns:tns=urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0 xmlns:rim=urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0> <tns:RegistryErrorList
I have an xml document like this... this xml doc provides content for webpages
I have an application which extracts data from an XML file using XPath. If
I have been trying to extract an e-mail address from a website using XPath.
I have a SOAP message (see below). Using Xpath, how can I extract the
Using XSLT and XPath 1.0, I have a string I want to escape for
I have the following XPATH line: //det[@nItem=1]/prod/cProd That successfully selects the desired node using
i am trying to do XML parsing using SAX by using xpath. but when

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.