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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:56:42+00:00 2026-06-11T16:56:42+00:00

Hi I have an xml as shown below <?xml version=1.0 encoding=UTF-8 standalone=yes?> <A> <B>

  • 0

Hi I have an xml as shown below

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<A>
    <B>
        <X1>
            <Name>ZZZsaqw</Name>
        </X1>
        <X1>
            <Name>ZZZsdasda</Name>
        </X1>
        <X1>
            <Name>ZZZsdsd</Name>
        </X1>
        <S>17000</S>
        <U>18000</U>
        <V>17000</V>
    <B>
    <C>
        <X1>
            <Name>ZZZasqw</Name>
        </X1>
        <X1>
            <Name>ZZZsdsd</Name>
        </X1>
        <X1>
            <Name>ZZ</Name>
        </X1>
        <S>17000</S>
        <U>18000</U>
        <V>17000</V>
    <C>
    <D>
        <X1>
            <Name>ZZZx</Name>
        </X1>
        <X1>
            <Name>ZZZzz</Name>
        </X1>
        <X1>
            <Name>ZZZsaa</Name>
        </X1>
        <S>17000</S>
        <U>18000</U>
        <V>17000</V>
    </D>
<A>

I am interested in the X1 tag. I need to read them respective of their parent tags which can be either B, C or D.
So at times I am interested only in X1 tags belonging to B sometimes belonging to C. How to do this? I used the DOM parser shown below but when I am counting them, it is showing the count as 9 where as it should have been 3. Please help me how to do it.

        NodeList plist = doc.getElementsByTagName("A");
        System.out.println("The length of A is pList is:"+plist.getLength());
        //get the contents of the A
        for (int temp = 0; temp < plist.getLength(); temp++)
        {
            Node nNode = plist.item(temp);
            if (nNode.getNodeType() == Node.ELEMENT_NODE)
            {
                //Element eElement = (Element) nNode;

                NodeList typicalCriticalPath = doc.getElementsByTagName("B");
                System.out.println("The length of B is:"+typicalCriticalPath.getLength());

                //get the contents of the typical critical path
                for(int temp1 = 0; temp1<typicalCriticalPath.getLength();temp1++)
                {
                    Node typCriticalPathNode = typicalCriticalPath.item(temp);
                    if (typCriticalPathNode.getNodeType() == Node.ELEMENT_NODE)
                    {
                        Element ele = (Element) typCriticalPathNode;
                        NodeList planItemSection = doc.getElementsByTagName("X1");
                        System.out.println("The length of X1 is:"+planItemSection.getLength());
                    }

                }

            }
        }
 //The output for this is like this-
 //The length of A is pList is:1
 //The length of B is:1
 //The length of X1 is:9

Can someone please point me where I am going wrong? What is to be done so that I can get the tags wrt parent tag only.

Thanks!

  • 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-11T16:56:43+00:00Added an answer on June 11, 2026 at 4:56 pm

    NodeList planItemSection = doc.getElementsByTagName(“X1”);

    That would be all X1 in the document.

    I think you want

    NodeList planItemSection = ele.getElementsByTagName(“X1”);

    , where ele is the parent element.

    You may also want to look into XPath for these kind of queries.

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

Sidebar

Related Questions

I have below string in javascript var output = '<?xml version=1.0 encoding=UTF-8 standalone=yes?><abc><xyz><xyzResponse><URL>http%3A%2F%2Flocalhost%3A8080%2Fnet%2Fxyz.do%3Fpartner%3Ddummy%26id%3Dba0e245f-ae67-40b6-986d-3242acea4c04</URL><StatusMsg>SUCCESS</StatusMsg><ID>hello.com</ID><AID>test</AID></xyzResponse></xyz></abc>'; I
I have an XML input as shown below: <?xml version=1.0 encoding=utf-8?> <Content> <section name=FileID/>
I have colors in my String.xml file, as shown below: <?xml version=1.0 encoding=utf-8?> <resources>
I have a simple XML file as shown below. <?xml version=1.0 encoding=UTF-8?> <myConfig> <datasets>
I have a message factory bean configured as shown below: <?xml version=1.0 encoding=UTF-8?> <beans
I have XML similar to the following <?xml version=1.0 encoding=utf-8?> <foo name=FooBar xmlns=http://mydomain/myapp/ver/myschema.xsd> <bars
I have defined a xml schema as below <?xml version=1.0 encoding=utf-8?> <xs:schema id=PacketTemplate targetNamespace=http://tempuri.org/PacketTemplate.xsd
I have an XML document that looks like this: <?xml version=1.0 encoding=UTF-8?> <xs:msgdata xmlns:xs=http://www.myCompany.com
I have an input xml as follows, <?xml version=1.0 encoding=utf-8 ?> <?xml-stylesheet type=text/xsl href=cdcatalog.xsl?>
I have the following schema: <?xml version=1.0 encoding=UTF-8?> <xs:schema xmlns:xs=http://www.w3.org/2001/XMLSchema xmlns:m=http://ws.mypackage.com xmlns:xmime=http://www.w3.org/2005/05/xmlmime elementFormDefault=qualified targetNamespace=http://ws.mypackage.com

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.