• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the tip. I have resolved the issue. getChildNodes() came in handy!
reply
    Bookmark Topic Watch Topic
  • New Topic