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

  • Home
  • SEARCH
  • 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 8530145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:11:35+00:00 2026-06-11T09:11:35+00:00

I am trying to read child node value with attribute value of a specific

  • 0

I am trying to read child node value with attribute value of a specific element using DOM parser..
My xml file:

    <?xml version="1.0" encoding="UTF-8"?>
<RootNode>
    <SubNode Sid="1">
        <title>some text</title>
        <data dId="1">some text</data>
        <data dId="2">some text</data>
        <ExData>1</ExData>
    </SubNode>
    <SubNode Sid="2">
        <title>some text</title>
        <data dId="1">some text</data>
        <data dId="2">some text</data>
        <data dId="3">some text</data>
        <data dId="4">some text</data>
        <data dId="5">some text</data>
        <ExData>1</ExData>
    </SubNode>
    <SubNode Sid="3">
        <title>some text</title>
        <data dId="1">some text</data>
        <data dId="2">some text</data>
        <data dId="3">some text</data>
        <ExData>1</ExData>
    </SubNode>
</RootNode>

i am trying to read data nodes value of a one SubNode. i have checked with below code:

private void parseDocument()
{
    Element docEle = dom.getDocumentElement();
    NodeList nl = docEle.getElementsByTagName("SubNode");
    if(nl!= null && nl.getLength()>0)
    {
        for(int i=0; i<nl.getLength();i++)
        {
            Element el = (Element)nl.item(i);
            InfoBean que = getInfoBean(el);
            InfoBeanSet.add(que);
        }
    }
}
private InfoBean getInfoBean(Element el)
{
    int sId = Integer.parseInt(el.getAttribute("Sid"));
    String title = getTextValue(el,"title");    

    NodeList SingleOptionNode = el.getElementsByTagName("data");
    int nodeLen = SingleOptionNode.getLength();
    if(SingleOptionNode != null && nodeLen>0)
    {
        for(int i=0; i<nodeLen; i++)
        {
            Element el1 = (Element)SingleOptionNode.item(i);
            NodeList nextOption = el1.getChildNodes();
            Node currentNode = (Node) nextOption.item(0);
            int dId = Integer.parseInt(el1.getAttribute("dId"));
            String data = currentNode.getNodeValue();
            opt.add(new Option(data, dId));
        }
    }
    String ExData = getTextValue(el,"ExData");
    InfoBean ifb = new InfoBean(sId,title,opt,ExData);
    return ifb;
}

it gives data node values of all 3 SubNodes. how to read one SubNode element child node values with attribute value.
Can i know the reason why am getting all data node value?
can i get some code examples how to read data node value of a one SubNode element..
Any help would appreciated.

  • 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-11T09:11:36+00:00Added an answer on June 11, 2026 at 9:11 am

    This line introduces a loop over all of the SubNode elements in your node list.

       for(int i=0; i<nl.getLength();i++)
    

    Try not doing that.

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

Sidebar

Related Questions

I'm trying to read a Collada XML file by iterating through a child node
I have been trying to read an xml file. I have to extract value
I am using orbeon and I am trying to read child element defined in
I am trying to read in an XML file that I have saved to
I am trying to read from a file and encrypt the data using AES
I'm trying to parse some XML (html) I downloaded using WebRequest.Create() and then read
On SQL Server 2008 R2, I am trying to read XML value as table.
I have a simple XML document I'm trying to read in with Python DOM
I'm trying to read from an XML file and use that to populate a
I am trying to read tags from XML using LibXML. I can print all

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.