OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Java - XMLReader and SAX Filters

[ Lists Home | Date Index | Thread Index ]


   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;
}
--------------------------------------------------------------------------------------------------





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS