aspose file tools*
The moose likes XML and Related Technologies and the fly likes generic parser 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 "generic parser" Watch "generic parser" New topic
Author

generic parser

pals meh
Greenhorn

Joined: May 11, 2005
Posts: 7
hi i have been asked to code a generic file parser to parse xml and csv files...Now for the xml files i am asked to code an sax parser and then use xpath to get specific values from elements...I am fairly new to these technologies..i would like to know if i can use xpath with the SAX interface and can anyone point to some resources that i could look at...
thanx
paryul
Rajagopal Manohar
Ranch Hand

Joined: Nov 26, 2004
Posts: 183
asked to code an sax parser


why not use an existing sax parser?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12825
    
    5
Seems to me that regular xpath requires a DOM of some sort to operate and thus can't be implemented with only SAX processing.
I suppose you could evaluate limited xpath expressions by keeping track of the SAX start and end element events.
Life will be a lot simpler if you are not required to implement namespaces!
Bill
pals meh
Greenhorn

Joined: May 11, 2005
Posts: 7
rajagopal,bill:Thanx for your replies.I finally got more info on what im supposed to do.This parser is part of a larger code which is supposed to track files sent into an enterprise system.Now the system has CSVfiles and XML files so what we wanna do is create a generic parser for both these formats.The purpose of this parsing is only to extract certain information from the file and log it to some database so that we know where the file is in the system.The code that im supposed to design will take in the file and based on a xpath query will extract the unique data from the field and then it will be logged.My question was since ive not had time yet to read up on xpath ,can it be used in this senario with a sax parser?I think i would have to read in the xpath string,tokenize it and then code it in such a way that i read in the info when that specific element is encountered during the sax parsing.Do you have any suggestions?

PM
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12825
    
    5
i would have to read in the xpath string,tokenize it and then code it in such a way that i read in the info when that specific element is encountered during the sax parsing.

I think you are on the right track there.
Figuring out how to represent the xpath logic will certainly be interesting!
I wonder if some sort of "rules engine" such as DROOLS or JESS would be any use or if it would just be overkill. Do you have any feeling for how complex the xpath queries may become?
Bill
pals meh
Greenhorn

Joined: May 11, 2005
Posts: 7
hey bill
I think the solution i thought off might work and i also dont have to be bothered about namespaces...:-)Its still a lot of work but thanx for ur input ..really appreaciate it

paryul
Santosh Pasupuleti
Ranch Hand

Joined: Aug 10, 2005
Posts: 97
Paryul,
You will use SAX or DOM on your xml data, but how do deal with the CSV file data with the generic parser?

Please share your solution with us.

Regards
Santosh
Eddy Lee Sin Ti
Ranch Hand

Joined: Oct 06, 2005
Posts: 135
For CSV or other arbitrary file format, you can develop your own reader that implements org.xml.sax.XMLReader, which used to generate SAX events.



The reader will generate events for the generic SAX parser to consume.

Hope this is helpful.


SCJP, SCWCD, SCJWS, IBM 700,IBM 701, IBM 704, IBM 705, CA Clarity Technical<br /> <br /><a href="http://eddyleesinti.blogspot.com" target="_blank" rel="nofollow">http://eddyleesinti.blogspot.com</a>
Noah Davidson
Greenhorn

Joined: Oct 07, 2005
Posts: 2
Payul,
I think you must be a really spiritual person to post a question like that. Am I right?

- Noah
pals meh
Greenhorn

Joined: May 11, 2005
Posts: 7
hey thanx eddy
Noah.I dont really understand how you came to that conclusion !!!
Could you please explain
Noah Davidson
Greenhorn

Joined: Oct 07, 2005
Posts: 2
hey payul,
well, you said 'I am fairly new to these technologies'. only a spiritual person is so honest. are you an iscon follower, i get a feeling that you are?
it takes a spiritual person to know one...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: generic parser