I have an XML stream I want to parse using SAX. What I actually want to do is simply echo out the XML stream to an output stream, but optionally filter out some of the tags or alter some of the attributes. Is there already a convenient "Echo" ContentHandler I can leverage to do this?
A:
Yes. Java trax/jaxp API's provide for this. http://download.oracle.com/javaee/1.4/api/javax/xml/transform/package-summary.html http://download.oracle.com/javaee/1.4/api/javax/xml/transform/stream/StreamSource.html http://download.oracle.com/javaee/1.4/api/javax/xml/transform/stream/StreamResult.html
So you'd architect the pipe as follows:
SAX input -> [ your result | custom input] -> Stream output
Where [ your result | custom input ] can be as simple as a class which bridges necessary SAX interfaces to make a ContentHandler able to provide the input for a SAX input source.