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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:44:17+00:00 2026-06-12T12:44:17+00:00

I have an XML config file that has just one parent and one child.

  • 0

I have an XML config file that has just one parent and one child. This will always be like this and never change. It looks something like this:

<parent>
   <child1>test</child1>
   <child2>123</child2>
</parent>

I want to use java DOM (org.w3c.dom.Document) to parse the XML into a TreeMap so that I can access the attributes as keys/values. I’m guessing I’d need to create a for loop that scans through the XML and adds the key (parent) and value (child) line by line?

  • 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-12T12:44:19+00:00Added an answer on June 12, 2026 at 12:44 pm

    You can traverse the XML document using JAXP APIs, you don’t need to know the structure or node names in advance

    InputStream is = new ByteArrayInputStream(xml.getBytes("UTF-8"));
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuilder = dbf.newDocumentBuilder();
    Document doc = docBuilder.parse(is);
    NodeList nodeList = doc.getChildNodes();
    

    and you can iterate on document and get the nodes and attributes

    for (int i = 0; i < nodeList.getLength(); i++) {
                Node node = nodeList.item(i);
                NamedNodeMap attributes = node.getAttributes();
    
    //...
    

    }

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

Sidebar

Related Questions

I have a component library. It has a manifest file that looks like this:
I just have a test. Config jndi in $CATALINA_HOME/conf/context.xml like below: <Resource name=jdbc/db auth=Container
I'm using an XML config file to populate my navigation using Zend_Navigation. I have
I have the following text in xml file: <Config Builder=LP Wizard> <Libraries> <Library Name=XCAMSource/>
In web.xml I have this <session-config> <session-timeout>2</session-timeout> </session-config> <listener> <listener-class>myapplication.SessionListener</listener-class> </listener> In the SessionListener.java
Currently, we use a giant configuration object that is serialized to/from XML. This has
I have a spring application that has configured log4j (via xml) and that runs
I have a need to have a config.xml file in my Eclipse project, and
I have this code that takes a file path that is obtained with the
I have two WARS: base-overlay example-app base-overlay has XML config files in src/main/webapp/WEB-INF/spring/*.xml .

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.