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

Java - XMLReader and SAX Filters


java xmlreader

   Hi,

  I'm using the below code to create a transformation pipeline using SAX and filters.
The xsl stylesheet is in file style.xsl and xml data is received in the xmlStream String.
Some static functions that I use are part of a class called SAXProcessing (that I also
show below).
  I can't see what isn't working in this code. I was first using a XMLFilterImpl object
to generate some xml ( instead of the XMLReader ) and all was working fine. But when
 I solved to replace it with a XMLReader and parse the xml data from a xml data stream
 the problems started...
now the only output I get are the text nodes in my xml data along with the inserted
doctype. It seems that my xsl is simply being ignored.

   Any suggestions?


         Cheers,

              Filipe

--------------------------------------------------------------------------------------------------
	XMLReader xmlReader = null;

	try {
		SAXParserFactory spfactory =
			SAXParserFactory.newInstance();

		spfactory.setValidating(false);

		SAXParser saxParser =
			spfactory.newSAXParser();

		xmlReader = saxParser.getXMLReader();

		XMLFilter xmlFilter =
			SAXProcessing.newXMLTransformerFilter("style.xsl");

		xmlFilter.setParent(xmlReader);

		TransformerHandler transHand =
			SAXProcessing.newTransformerHandlerSerializer( new StreamResult(System.out));

		xmlFilter.setContentHandler(transHand);

		xmlReader.parse( new InputSource( new StringReader(xmlStream)));

	} catch (Exception e) {
		...
	}
--------------------------------------------------------------------------------------------------

My SAXProcessing functions:

--------------------------------------------------------------------------------------------------
public static XMLFilter newXMLTransformerFilter(String xslFileName){
	try {
		SAXTransformerFactory saxTFactory =
			(SAXTransformerFactory) TransformerFactory.newInstance();

		return saxTFactory.newXMLFilter( new StreamSource(xslFileName));

	} catch (Exception e) {
		e.printStackTrace();
		System.exit(1);
	}
	return null;
}

private static TransformerHandler newTransformerHandlerSerializer(StreamResult result){
	try {
		SAXTransformerFactory saxTFactory =
			(SAXTransformerFactory) TransformerFactory.newInstance();
		TransformerHandler transHand = saxTFactory.newTransformerHandler();

		transHand.setResult( result );
		Transformer transformer = transHand.getTransformer();
		transformer.setOutputProperty(OutputKeys.METHOD, method);
		transformer.setOutputProperty(OutputKeys.INDENT, "yes");
		transformer.setOutputProperty(
						OutputKeys.DOCTYPE_PUBLIC,
						"-//W3C//DTD HTML 4.01//EN");
		transformer.setOutputProperty(
						OutputKeys.DOCTYPE_SYSTEM,
						"http://www.w3.org/TR/html4/strict.dtd");

		transformer.setOutputProperty(OutputKeys.ENCODING, "ISO-8859-1");
		transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
		return transHand;

	} catch (Exception e) {
		e.printStackTrace();
		System.exit(1);
	}
	return null;
}
--------------------------------------------------------------------------------------------------


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
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

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.