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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:50:00+00:00 2026-05-29T19:50:00+00:00

I want to convert an java string containing xml to a w3c dom document

  • 0

I want to convert an java string containing xml to a w3c dom document object.

I first searched all over the place and came up with some good examples here on stackoverflow.
But sadly I can get them working!

Apperently my code is not working 100%.

It seems like it parses the string but there are no values in the nodes.
This is what I got so far!

Document newDoc = null;

InputSource is = new InputSource();
is.setCharacterStream(new StringReader(TestFiles.RSS_FEED_FILE_2));

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = null;
builder = factory.newDocumentBuilder();
newDoc = builder.parse(is);

When I do a sysout afterwards like this:

System.out.println(newDoc.getDocumentElement().getElementsByTagName("channel").item(0)
.getNodeValue());

I got null as output while using this sysout:

System.out.println(newDoc.getDocumentElement().getElementsByTagName("channel").item(0));

I got as output: [channel: null]

So I have an object else it would throw some null pointer exceptions but it doesn’t contain any values inside ?!

The content of the constant is this :

public final static String RSS_FEED_FILE_2 =    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + 
                                            "<rss version=\"2.0\">\n" + 
                                            "<channel>\n" + 
                                            "<title>sunday</title>\n" + 
                                            "<link>http://www.google.nl</link>\n" + 
                                            "<pubDate>2012-02-05 20:58</pubDate>\n" + 
                                            "<lastBuildDate>2012-02-08 09:48</lastBuildDate>\n" + 
                                            "<description>blabla </description>\n" + 
                                            "<item>\n" + 
                                            "<title><![CDATA[title]]></title>\n" + 
                                            "<link><![CDATA[http://www.google.nl]]></link>\n" + 
                                            "<guid><![CDATA[2266610]]></guid>\n" + 
                                            "<source><![CDATA[sunday]]></source>\n" + 
                                            "<author><![CDATA[me]]></author>\n" + 
                                            "<description><![CDATA[blalbalavblabllllll!]]></description>\n" + 
                                            "</item>\n" + 
                                            "</channel>\n" + 
                                            "</rss>";

Does anybody have a solution or a hint?

  • 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-29T19:50:02+00:00Added an answer on May 29, 2026 at 7:50 pm

    This is quite a common gotcha. The behaviour of getNodeValue() depends on the subclass of Node. In the case of an Element, getNodeValue() will always return null (see the table in the Node javadoc for behaviour of other subclasses).

    Consider using getTextContent() if you want to debug the XML document.

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

Sidebar

Related Questions

I want to convert an XML document containing many elements within a node (around
I want to convert string Date into Timestamp in java. The following coding i
I have a string with special characters in Java. [^\\]*\\ I want to convert
In java i have two variables String string; int integerValue; I want to convert
How can I convert a String to Object? Actually, I want to set clientSession.setAttribute(username,
I want to convert List<String> to List<Object> . One of the existing methods is
I want to convert a character array to a string object using the toString()
I want to convert a java string that contains UTF-8 characters to a format
if I want to convert a string into an int in java do you
I want to convert a primitive to a string, and I tried: myInt.toString(); This

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.