• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need to parse a xml which doesn't have a parent node.

 
Gopi Chand Maddula
Ranch Hand
Posts: 40
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Java Ranch,

While going through some requirements doc i came to know that i have to parse an xml which has not even having a parent node.

First of all i was wondering that can we define any xml without having a parent node?

Irrespective of the rules for writing the xml i thought of trying and written a method which takes an xmlstring as input and gives map as output.

Below is my method snippet



and my xml which has to be parsed looks like this.


but even i try to execute the method i am getting the response as expected which is




can anyone help me in parsing the xml, and let me know the mistake i was doing.

 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Add your own parent node before parsing. eg


 
Gopi Chand Maddula
Ranch Hand
Posts: 40
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your Reply.

That was a one good solution. But i do want to know that is there is any rule that an XML may or may not contain the Parent Node.
But as i am using DOM to parse the XML, i require the parent node for sure.

Please let me know whether there is any other possibility to parse the XML which doesn't have a parent Node.

I am Using DOM Parser for now. Is it the good practice or else i should go for SAX. Please Help me which is better way to parse and WHY?
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If it doesn't have a root node, then it's not well-formed - and thus it isn't even XML. Check the XML specification for details on what makes a well-formed XML document.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic