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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T11:59:31+00:00 2026-05-21T11:59:31+00:00

Lets say i have this XML file: <attributes> <units> <civilians> <unit> <name>Settler</name> <stats> <attack>26</attack>

  • 0

Lets say i have this XML file:

<attributes>
  <units>
    <civilians>
      <unit>
        <name>Settler</name>
        <stats>
          <attack>26</attack>
          <defence>7</defence>
        </stats>
        <costs>
          <lumber/>
          <iron/>
        </costs>
      </unit>
      <unit>
        <name>Infantry</name>
        <stats>
          <attack>33</attack>
          <defence>7</defence>
        </stats>
        <costs>
          <lumber/>
          <iron/>
        </costs>
      </unit>
    </civilians>
  </units>
</attributes>

Does getElementsByTagName(“attack”) on the node attributes return a NodeList with the attack element containing 26 at first position and the attack element containing 33 at second position?

I’ve been thinking this is the case but it doesn’t seem to work.

If it isn’t as simple as this; what is a good way to grab all attack values from the XML file? Maybe the XML file itself is badly structured?

Edit: Ah. I get the nodes now, and .getTextContent() rather than .getNodeValue() solved my problems. Sorry for the inconvenience.

  • 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-21T11:59:31+00:00Added an answer on May 21, 2026 at 11:59 am

    Dom Core 2 Spec says:

    getElementsByTagName

    Returns a NodeList of all descendant Elements with a given tag
    name, in the order in which they are
    encountered in a preorder traversal of
    this Element tree.

    And Dom Core 3 Spec says:

    getElementsByTagName

    Returns a NodeList of all descendant Elements with a given tag
    name, in document order.

    So your expectations for the function are correct. If that’s not what you’re getting it would be a bug in your code or in the library you’re using.

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

Sidebar

Related Questions

Let's say that I have something like this in my web.xml file. <filter name=foo>
lets say i have an xml file path.xml that goes like this: <paths> <path
Lets say I have this XML file: <weather> <temp>24.0</temp> <current-condition iconUrl=http://....>Sunny</current-condition> </weather> I'm trying
I'm trying to format a table from XML. Lets say I have this line
let's say, I have this xml file: <?xml version=1.0 encoding=UTF-8 ?> <TimeSeries> <timeZone>1.0</timeZone> <series>
Lets say I have the following XML file: <?xml version=1.0 encoding=utf-8?> <Customers xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:noNamespaceSchemaLocation=Customer.xsd>
Let's say I have an XML file that looks like this: <a id=x> <b>
I have made following relative layout in an xml file lets say add_relative_layout.xml <?xml
i have one xml file. lets say sample.xml with random position of tabs and
Just as an example, lets say I have a customerX.xml file that I've unmarshalled

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.