Can you pass a parameter to the contenthandler in SAX?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Adam_Rubin
Posted On:   Monday, August 13, 2001 02:37 PM

Hi all, Hopefully someone can shed some light on this one for me. I have a servlet. That servlet is passed a parameter (ARTICLE_ID). I then need to parse a large (100+mb) xml file to find the element that has that paramenter as one of it's attributes. As in: blah Once I find the corresponding xml node, I need to grab it's characters ("blah") and drop them into a variable for later use. I'm new to the java/xml world, but what I've learned is that for large xml files i should use SAX. So I wrote some code using SAX to create a new contenthandler and parse the document. No problem... but now I can't seem to figure out how I can pass   More>>

Hi all,


Hopefully someone can shed some light on this one for me.


I have a servlet. That servlet is passed a parameter (ARTICLE_ID). I then need to parse a large (100+mb) xml file to find the element that has that paramenter as one of it's attributes. As in:



blah


Once I find the corresponding xml node, I need to grab it's characters ("blah") and drop them into a variable for later use.



I'm new to the java/xml world, but what I've learned is that for large xml files i should use SAX. So I wrote some code using SAX to create a new contenthandler and parse the document. No problem... but now I can't seem to figure out how I can pass that servlet paramenter to the contenthandler so that while I'm parsing the xml file I can stop one I've found what I'm looking for.


Am I way off on this one? Is there a piece missing that I should know about (such as xsl or xalan which I don't really know much about)?


Thanks much,

Adam

   <<Less

Re: Can you pass a parameter to the contenthandler in SAX?

Posted By:   Adam_Rubin  
Posted On:   Tuesday, August 14, 2001 08:24 PM

OK- no takers... So I'll answer my own question :)


After several hours of banging my head against the wall, I found the solution in the xalan/xpath combo.


xalan processes the document using a query passed by xpath. The result is dropped into a nodeList and from there it's a matter of iterating that list to grab specifically what you need.


A few URL's I found very helpful:


http://www.zvon.org/HTMLonly/XPathTutorial/General/examples.html


http://xml.apache.org/xalan-j/apidocs/index.html


http://triton.cc.gatech.edu/ubicomp/411





-Adam

About | Sitemap | Contact