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

The Archive Base Latest Questions

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

Possible Duplicate: how to retrieve element value of XML using Java? I am trying

  • 0

Possible Duplicate:
how to retrieve element value of XML using Java?

I am trying to parse a xml file with java using dom.
The xml looks like this:

<documents>
  <document>
    <element name="doctype">
      <value>Circular</value>
    </element>
  </document>
</documents>

Geting the root node “documents” and also the child node “document” is easy. But I can’t get the value of the element with the name “doctype” (I want to store the value “Circular” in a database). Can someone help me please?

  • 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-08T03:12:03+00:00Added an answer on June 8, 2026 at 3:12 am

    You could use the following XPath to get the data you are looking for:

    /documents/document/element[@name='doctype']/value
    

    Demo

    The following demo code demonstrates how to execute that XPath against your DOM. This application will run in any standard Java SE 5 (or newer) install.

    package forum11578831;
    
    import javax.xml.parsers.*;
    import javax.xml.xpath.*;
    import org.w3c.dom.Document;
    
    public class Demo {
    
        public static void main(String[] args) throws Exception {
            DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = domFactory.newDocumentBuilder();
            Document dDoc = builder.parse("src/forum11578831/input.xml");
    
            XPath xPath = XPathFactory.newInstance().newXPath();
            String string = (String) xPath.evaluate("/documents/document/element[@name='doctype']/value", dDoc, XPathConstants.STRING);
            System.out.println(string);
        }
    
    }
    

    input.xml

    I have expanded the XML document to contain element elements with name attributes with values other that doctype to demonstrate that the XPath works.

    <documents>
      <document>
        <element name="foo">
          <value>FOO</value>
        </element>
        <element name="doctype">
          <value>Circular</value>
        </element>
        <element name="bar">
          <value>BAR</value>
        </element>
      </document>
    </documents>
    

    Output

    The result of executing the XPath is the very String you are looking for:

    Circular
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What is the reg expression for this using javascript How to retrieve
Possible Duplicate: how to display a pdf file in jsp using servlet I retrieve
Possible Duplicate: How to retrieve user's current city name? using the following methods i
Possible Duplicate: What format is this? How do i retrieve this one. I'm not
Possible Duplicate: Retrieve Windows Experience Rating Using .NET, is there a way to programmatically
Possible Duplicate: Post data and retrieve the response using PHP Curl? I want to
Possible Duplicate: Retrieve JIT output Is this possible to do, and if so how
Possible Duplicate: File creation time In PHP, how to retrieve the files contained into
I want to retrieve all case-insensitive duplicate entries from an array. Is this possible
Possible Duplicate: retrieve email using PHP and pop3 - what is your technique? 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.