• 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

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

 
Ranch Hand
Posts: 41
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Add your own parent node before parsing. eg


 
Gopi Chand Maddula
Ranch Hand
Posts: 41
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic