[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Troubles with SAX

Subject: RE: Troubles with SAX
From: "Andrew Welch" <AWelch@xxxxxxxxxxxxxxx>
Date: Fri, 19 Mar 2004 09:21:09 -0000
sax parser parse bufferedinputstream
> ------------------
> second code
> 
> //using SAX, get troubles
> File stylesheet = new File("article.xsl");
> File datafile = new File("article.xml");
> 
> BufferedInputStream bis = new BufferedInputStream(new 
> FileInputStream(datafile)); InputSource input = new InputSource(bis);
> 
> SAXParserFactory spf = SAXParserFactory.newInstance(); 
> SAXParser parser = spf.newSAXParser(); XMLReader reader = 
> parser.getXMLReader();
> 
> SAXTransformerFactory stf = 
> (SAXTransformerFactory)TransformerFactory.newInstance();
> XMLFilter filter = stf.newXMLFilter(new StreamSource(stylesheet));
> 
> filter.setParent(reader);
> 
> StreamResult result = new StreamResult(new 
> FileOutputStream("article.html"));
> 
> Transformer transformer = stf.newTransformer();
> SAXSource transformSource = new SAXSource(filter, input); 
> transformer.transform(transformSource, result);
> 
> --------------------------------------------------------------

I'm not too sure what you are trying to do there, but the code for
parsing your xml through a SAX filter into a transform usually looks
like this:

//create a handler passing in your stylesheet
SAXTransformerFactory stf = (SAXTransformerFactory)
TransformerFactory.newInstance();
TransformerHandler handler = stf.newTransformerHandler(stylesheet);

//create a SAX filter using your own filter
XMLFilter myCustomSaxFilter = MyCustomSaxFilter();

//attach it to an xml reader - adjust string for the parser you're using
myCustomSaxFilter.setParent(XMLReaderFactory.createXMLReader("org.apache
.crimson.parser.XMLReaderImpl")); 

//attach it to the handler
myCustomSaxFilter.setContentHandler(hander);

//call parse to instigate the filter and transform
myCustomSaxFilter.parse(yourXml);


cheers
andrew

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.