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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:15:39+00:00 2026-05-31T12:15:39+00:00

I have an xml file which looked something like this… <RootElementTag> <ChildElementTag1 attribute1=value1 />

  • 0

I have an xml file which looked something like this…

<RootElementTag>
   <ChildElementTag1 attribute1="value1" />
   <ChildElementTag1 attribute1="value2" />
   <ChildElementTag1 attribute1="value4" />
</RootElementTag>

I had to retrieve all the “ChildElementTag1” nodes and process them in the order in which they appear in the file. I used org.w3c.dom.Document.getElementsByTagName("ChildElementTag1"); which returned me a NodeList in the order in which it appears in the xml file.

Now the xml changed a bit and a new Child node with a different tag name “ChildElementTag2” is included.

<RootElementTag>
   <ChildElementTag1 attribute1="value1" />
   <ChildElementTag1 attribute1="value2" />
   <ChildElementTag2 attribute2="value3" />
   <ChildElementTag1 attribute1="value4" />
   <ChildElementTag2 attribute2="value5" />
</RootElementTag>

Is there a way to get all the 5 Child Element Nodes in the above xml snippet in the order in which they appear.

Note:- I did see org.w3c.dom.Document.getElementById() method which would need me to introduce an “id” attribute to each child node and order them based on their “id” attribute value. As of now I am not taking that approach hoping there is an easier way of doing this.

  • 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-31T12:15:40+00:00Added an answer on May 31, 2026 at 12:15 pm

    Call getChildNodes() on the RootTagElement node.


    The javadoc for this method does not mention that the NodeList returned in the order in which it appears in the document.

    I suspect you’ll find they are in the same order as they appear in the document. OTOH, you might also look to methods listed just below the one to which I linked. Specifically getFirstChild() & getNextSibling() (which you would call on the first child, then repeatedly until null).

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

Sidebar

Related Questions

I have an xml file which looks like this <?xml version=1.0 encoding=UTF-8 ?> <BulkDataExchangeRequests
I have an XML file which has many section like the one below: <Operations>
I have an XML file which I'd like to parse into a non-XML (text)
I have written xml file which contains html tags as element like <component> <input
I have an XML file like this: <LogFiles> <Type1> <File> <Component>1</Component> <Path>C:\TypeFiles</Path> <FileName>a.txt</FileName> </File>
I have XML file which is looks like: <Report> <Total> <RecordValues> <Record> <FieldValue fieldName=index
I have an XML file which I need to parse using PHP and send
I have an XML file which XML parser choke on. A part of it
I have an XML file which has to be transformed using XSLT, I am
I have a xml file which contains arabic characters.When i try to parse a

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.