Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Parsing XML string using Java Program

 
Raghuraman Muthuswamy
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,
I am trying to parse a XML file without using SAX or DOM. I would like to develop a simple parser. If you provide me some tutorials about this it will be very useful. The main thing is the XML file should be parsed by Java Application Program.

Thanks in advance,

regards,
Raghu
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thinking out loud here, parsing XML file without SAX and DOM -

To me this means, read the XML file as a text file and manipulate what various characters mean. Say if you encounter a '<' symbol, possible indication of a start or end element. If the '<' char is immediately followed by a '/' char, it indicates a end element.

Unfortunately I don't have any links handy to that detail, but any text parsing java code could be used as a tutorial.
I would love to see other thoughts on this.
Thanks.

- m
 
Raghuraman Muthuswamy
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Madhav,
Even Iam thinking the same way. Have to check for each < and > tags and put the tag value in a string. if you provide me with some text parsing tutorials it will be very helpful.

Thanks in advance,

Regards
Raghu
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13056
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember that XML has requirements for nesting elements to make "well formed" XML so parsing will resemble processing algebraic notation.
Since XML parsers have been part of the standard Java release since Java 1.4 , any Application Program can parse XML.
A number of open source simple XML parsers have been developed - for example the kXML project.
You might find inspiration there.
Bill
 
Balaji Loganathan
author and deputy
Bartender
Posts: 3150
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Raghuraman Muthuswamy:
if you provide me with some text parsing tutorials it will be very helpful.



I remember William Brogden mentioned about using StringTokenzier or some related API for a question related to reading a csv like text file. Cant get that particular post.
I guess u r interested in developing ur own parser, i would suggest you to looking into the source of kXML,Xerces, Crimson and see how they have done it ??
Cheers
Balaji
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic