aspose file tools*
The moose likes XML and Related Technologies and the fly likes need to parse a xml which doesn't have a parent node. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "need to parse a xml which doesn Watch "need to parse a xml which doesn New topic
Author

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

Gopi Chand Maddula
Ranch Hand

Joined: May 11, 2010
Posts: 40

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

Joined: Sep 07, 2004
Posts: 781

Add your own parent node before parsing. eg



Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
Gopi Chand Maddula
Ranch Hand

Joined: May 11, 2010
Posts: 40

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
Marshal

Joined: Mar 22, 2005
Posts: 42286
    
  64
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.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need to parse a xml which doesn't have a parent node.