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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:33:38+00:00 2026-05-23T14:33:38+00:00

Having a bit of trouble parsing xml with dom and DocumentBuilder. I’m able to

  • 0

Having a bit of trouble parsing xml with dom and DocumentBuilder. I’m able to get it working, but I guess I get a bit confused with all the child nodes, etc.

Here’s the XML I’m working with:

<?xml version="1.0" encoding="utf-8"?>
<LabTests>
    <LabTest type="specialty" name="Anti-FXa activity" id="antiFXa" order="16">
        <values unit="U/mL" default="N/A">
            <value type="increased" val="0">
                <conditions>
                    <condition>Heparin effect</condition>
                </conditions>
            </value>
            <value type="normal" val="">
                <conditions></conditions>
            </value>
            <value type="decreased" val="">
                <conditions></conditions>
            </value>
        </values>
    </LabTest>
    <LabTest type="general" name="aPTT" id="aPTT" order="">
        <values unit="secs" default="N/A">
            <value type="increased" val="">
                <conditions>
                    <condition>Acquired hemophilia</condition>
                    <condition>Acquired vWD</condition>
                    <condition>DIC</condition>
                    <condition>Dysfibrinogenemia</condition>
                    <condition>FI deficiency</condition>
                    <condition>FII deficiency</condition>
                    <condition>FII/IIa inhibitors</condition>
                    <condition>FIX deficiency</condition>
                    <condition>FIX inhibitors</condition>
                    <condition>FV deficiency</condition>
                    <condition>FV inhibitors</condition>
                    <condition>FVIII deficiency</condition>
                    <condition>FX deficiency</condition>
                    <condition>FX inhibitors</condition>
                    <condition>FXI deficiency</condition>
                    <condition>FXI inhibitors</condition>
                    <condition>FXII deficiency</condition>
                    <condition>FXII inhibitors</condition>
                    <condition>Heparin effect</condition>
                    <condition>Liver disease effect</condition>
                    <condition>Lupus anticoagulant</condition>
                    <condition>Monoclonal gammopathy</condition>
                    <condition>Vitamin K deficiency</condition>
                    <condition>vWD type 1</condition>
                    <condition>vWD type 2</condition>
                    <condition>vWD type 3</condition>
                    <condition>Warfarin effect</condition>
                </conditions>
            </value>
            <value type="normal" val="">
                <conditions>
                    <condition>DIC</condition>
                    <condition>Dysfibrinogenemia</condition>
                    <condition>FVII deficiency</condition>
                    <condition>FXIII deficiency</condition>
                    <condition>FVII inhibitors</condition>
                    <condition>Liver disease effect</condition>
                    <condition>Lupus anticoagulant</condition>
                    <condition>Monoclonal gammopathy</condition>
                    <condition>Vitamin K deficiency</condition>
                    <condition>vWD type 1</condition>
                    <condition>vWD type 2</condition>
                    <condition>vWD type 3</condition>
                    <condition>Warfarin effect</condition>
                </conditions>
            </value>
            <value type="decreased" val="">
                <conditions>
                    <condition>DIC</condition>
                </conditions>
            </value>
        </values>
    </LabTest>
</LabTests>

what I’m trying to do is grab hold of each LabTest element and, within each of those elements, grab hold of the value elements (and grab the value of type) and, within the value element, grab hold of all of the condition elements.

In the end, I want something like a Map<String, HashMap<String, ArrayList<String>>, where the String is the LabTest name and the HashMap uses the type (e.g. decreased, increased, etc) for the key and then fills up the ArrayList with the conditions for that value type.

Confusing enough?

Basically, I just need an example, I think, of how to loop through and grab each LabTest with its “value” elements, and each of the “condition” elements under those “value” elements.

  • 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-23T14:33:39+00:00Added an answer on May 23, 2026 at 2:33 pm

    That should work as you described:

    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    
    Document doc = builder.parse("input.xml");
    
    NodeList labTestList = doc.getElementsByTagName("LabTest");
    for (int i = 0; i < labTestList.getLength(); ++i)
    {
        Element labTest = (Element) labTestList.item(i);
        String labTestType = labTest.getAttribute("type");
    
        NodeList valueList = labTest.getElementsByTagName("value");
        for (int j = 0; j < valueList.getLength(); ++j)
        {
            Element value = (Element) valueList.item(j);
            String valueType = value.getAttribute("type");
    
            NodeList conditionList = value.getElementsByTagName("condition");
            for (int k = 0; k < conditionList.getLength(); ++k)
            {
                Element condition = (Element) conditionList.item(k);
                String conditionText = condition.getFirstChild().getNodeValue();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a bit of trouble parsing an xml file with a namespace the
Having a bit of trouble. I need to find all of the countries that
Having a bit of trouble using the List.Find with a custom predicate i have
Having a bit of trouble wrapping my head around this one. I'm sure the
Im having a bit of trouble getting my JSON to be recognised by my
I'm having a bit of trouble iterating and retrieving width() values. $(.MyClass).each( function ()
I'm having a bit of trouble with a C# program I'm writing and it'd
I'm having a bit of trouble with the mktime function. On my production server,
I'm having a bit of trouble loading pages into an already-existing colorbox. I have
I'm having a bit of trouble figuring out exactly why my report will not

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.