• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Convert String of XML to Document object is null all the time  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to parse a XML string into `org.w3c.dom.Document` object.

I have looked at solutions provided [here](xml - How to convert String to DOM Document object in java? - Stack Overflow), [here](How to create a XML object from String in Java? - Stack Overflow) and a few other blogs that give a variation of the same solution. But the `Document` object's #Document variable is always null and nothing gets parsed.

Here is the XML



The constructor XMLMappingValidator object's code is as follows




When I call I get

Clearly, the parse is failing. But I don't understand why.

Any suggestions/help is greatly appreciated.

Thanks
 
Sheriff
Posts: 23137
45
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, the parse isn't failing at all. Clearly the parse produces a Document object whose value is null. If you look at the API documentation for the org.w3c.dom.Node interface it tells you that the nodeName of a Document node is "#document" and that the nodeValue of a Document node is null -- which is exactly what you're seeing there. So you've got a perfectly normal Document object. What that means is only that the nodeValue of a Document object is not a very useful thing.
 
anupam kumar prasad
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the tip. I have resolved the issue. getChildNodes() came in handy!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!