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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:05:43+00:00 2026-05-28T07:05:43+00:00

I have an XML file as follows. When I use getElementsByTagName(LEVEL2_ID) , I do

  • 0

I have an XML file as follows.

When I use getElementsByTagName("LEVEL2_ID"), I do get a NodeList with Nodes, but those Nodes have NULL values (in other words, getNodeValue() on each result node will return NULL). Why is this? I need to get the contents value of each node, in this case 2000.

XML:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Root>
    <Date>01/17/2012</Date>
    <LEVEL1>
        <LEVEL1_ID>1000</LEVEL1_ID>

        <LEVEL2>
           <LEVEL2_ID>2000</LEVEL2_ID>
        </LEVEL2>
    </LEVEL1>
</Root>

In Java, printing the Value of the 1st node obtained with getElementsByTagName() returns NULL:

NodeList nodes = document.getElementsByTagName("LEVEL2_ID");

System.out.println("Value of 1st node: " + nodes.item(0).getNodeValue());
  • 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-28T07:05:44+00:00Added an answer on May 28, 2026 at 7:05 am

    That is defined in the specification. Element nodes’ nodeValue is null.

    nodeValue of type DOMString: The value of this node, depending on its type; see the table above. When it is defined to be null, setting it has no effect.

    If you want to get the text content of each node, you have to iterate over all text node descendants and concatenate their value.

    That said, the API implementation you are using might offer a method to directly retrieve the text content of an element. For example, PHP’s DOMNode has a $textContent property.

    If, as in your case, the element’s only child is actually the text node you want, you can simply access its value:

    element.getFirstChild().getNodeValue()
    
    • 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 as follows, and I'm trying to read the content
I have an XML document as follows: <directory> <file><monitored>0</monitored> <xferStatus>1</xferStatus> <name>test1.txt</name> <size>7</size> <created>03/31/10 11:30:02
I would like to have an xml config file as follows: <?xml version=1.0 encoding=utf-8
i have tried several methods of trying to extract values from an XML file
I have created a custom Button as follows. file : buttoncontrol.xml <?xml version=1.0 encoding=utf-8?>
What is the easiest way to convert xml to html? I have xml file
I have an XML file that starts like this: <Elements name=Entities xmlns=XS-GenerationToolElements> I'll have
I have an xml file providing data for a datagrid in Flex 2 that
I have an XML file, which I open in F# like this: let Bookmarks(xmlFile:string)
I have an xml file where I need to comment out a whole piece

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.