This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Parsing XML string using Java Program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Parsing XML string using Java Program" Watch "Parsing XML string using Java Program" New topic

Parsing XML string using Java Program

Raghuraman Muthuswamy
Ranch Hand

Joined: Mar 18, 2003
Posts: 73
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,

Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
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.

- m

Take a Minute, Donate an Hour, Change a Life
Raghuraman Muthuswamy
Ranch Hand

Joined: Mar 18, 2003
Posts: 73
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,

William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13001
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.
Balaji Loganathan
author and deputy

Joined: Jul 13, 2001
Posts: 3150
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 ??

Spritle Software Blogs
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Parsing XML string using Java Program
It's not a secret anymore!