Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

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: 23703
50
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!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!