简体   繁体   中英

Filter XML stream using SAX

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM