|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Troubles with SAX
> ------------------
> 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








