• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

generic parser

 
pals meh
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
asked to code an sax parser


why not use an existing sax parser?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Noah Davidson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Payul,
I think you must be a really spiritual person to post a question like that. Am I right?

- Noah
 
pals meh
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey thanx eddy
Noah.I dont really understand how you came to that conclusion !!!
Could you please explain
 
Noah Davidson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic