net.sourceforge.saxadapter.examples.roundtrip
Class XMLWriter
java.lang.Object
|
+--org.xml.sax.helpers.XMLFilterImpl
|
+--net.sourceforge.saxadapter.PipelineBase
|
+--net.sourceforge.saxadapter.examples.roundtrip.XMLWriter
- All Implemented Interfaces:
- org.xml.sax.ContentHandler, org.xml.sax.ext.DeclHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler, org.xml.sax.ext.LexicalHandler, org.xml.sax.XMLFilter, org.xml.sax.XMLReader
- public class XMLWriter
- extends PipelineBase
This utility class is a SAX Pipeline component that writes the source
document out to the Writer that is set in setWriter(). This is meant
as an example of how PipelineBase can be subclassed to easily provide the
functionality necessary to make an XMLFilter a functional pipeline
component.
This is one example of how you can "round-trip" an XML document, which means
parsing and writing out the document in a single pass. See
XMLCallbackWriter for an example using the SAXAdapter utility. This
implementation has the advantage of full access to ContentHandler events
such as startDocument and can provide more detailed parsing location
information for errors using the Locator interface and SAXParseException
- Author:
- Mark Priest
Method Summary |
static void |
main(java.lang.String[] args)
This main method takes an XML document as input and writes it out to
standard output using the XMLWriter |
protected void |
onCharacters(char[] ch,
int start,
int length)
|
protected void |
onEndDocument()
|
protected void |
onEndElement(java.lang.String argNamespaceURI,
java.lang.String argLocalName,
java.lang.String argQName)
|
protected void |
onStartDocument()
|
protected void |
onStartElement(java.lang.String argNamespaceURI,
java.lang.String argLocalName,
java.lang.String argQName,
org.xml.sax.Attributes argAtts)
|
protected void |
onStartPrefixMapping(java.lang.String prefix,
java.lang.String uri)
|
void |
setWriter(java.io.Writer argOut)
|
Methods inherited from class net.sourceforge.saxadapter.PipelineBase |
attributeDecl, characters, comment, elementDecl, endCDATA, endDocument, endDTD, endElement, endEntity, endPrefixMapping, externalEntityDecl, getContentHandler, getProperty, ignorableWhitespace, internalEntityDecl, onEndPrefixMapping, onIgnorableWhitespace, onProcessingInstruction, onSetDocumentLocator, onSkippedEntity, parse, parse, processingInstruction, reset, setContentHandler, setDocumentLocator, setProperty, skippedEntity, startCDATA, startDocument, startDTD, startElement, startEntity, startPrefixMapping |
Methods inherited from class org.xml.sax.helpers.XMLFilterImpl |
error, fatalError, getDTDHandler, getEntityResolver, getErrorHandler, getFeature, getParent, notationDecl, resolveEntity, setDTDHandler, setEntityResolver, setErrorHandler, setFeature, setParent, unparsedEntityDecl, warning |
Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
XMLWriter
public XMLWriter()
XMLWriter
public XMLWriter(org.xml.sax.XMLReader argReader)
setWriter
public void setWriter(java.io.Writer argOut)
onStartElement
protected void onStartElement(java.lang.String argNamespaceURI,
java.lang.String argLocalName,
java.lang.String argQName,
org.xml.sax.Attributes argAtts)
throws org.xml.sax.SAXException
- Overrides:
onStartElement
in class PipelineBase
onCharacters
protected void onCharacters(char[] ch,
int start,
int length)
throws org.xml.sax.SAXException
- Overrides:
onCharacters
in class PipelineBase
onEndElement
protected void onEndElement(java.lang.String argNamespaceURI,
java.lang.String argLocalName,
java.lang.String argQName)
throws org.xml.sax.SAXException
- Overrides:
onEndElement
in class PipelineBase
onStartPrefixMapping
protected void onStartPrefixMapping(java.lang.String prefix,
java.lang.String uri)
throws org.xml.sax.SAXException
- Overrides:
onStartPrefixMapping
in class PipelineBase
onStartDocument
protected void onStartDocument()
throws org.xml.sax.SAXException
- Overrides:
onStartDocument
in class PipelineBase
onEndDocument
protected void onEndDocument()
throws org.xml.sax.SAXException
- Overrides:
onEndDocument
in class PipelineBase
main
public static void main(java.lang.String[] args)
- This main method takes an XML document as input and writes it out to
standard output using the XMLWriter
- Parameters:
args
- the first and only argument is the path to an XML file
in the classpath of the JVM