net.sourceforge.saxadapter.examples.roundtrip
Class XMLCallbackWriter

java.lang.Object
  |
  +--net.sourceforge.saxadapter.examples.roundtrip.XMLCallbackWriter
All Implemented Interfaces:
SAXTagHandler

public class XMLCallbackWriter
extends java.lang.Object
implements SAXTagHandler

This utility class writes the source document out to the Writer that is set in setWriter(). This is an example of how you can use the SAXAdapter to "round-trip" an XML document, which means parsing and writing out the document in a single pass.

Author:
Mark Priest

Constructor Summary
XMLCallbackWriter()
           
 
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 XMLCallbackWriter
 void onEndTag(java.lang.String argTagNamespace, java.lang.String argLocalTagName, java.lang.String argQName, java.util.Map argContext, NamespaceContext argNamespaceContext)
          Called by the SAXAdapter when an end tag, for which this callback interface has been registered, has been encountered.
 void onStartTag(java.lang.String argTagNamespace, java.lang.String argLocalTagName, java.lang.String argQName, org.xml.sax.Attributes argAttributes, java.lang.StringBuffer argText, java.util.Map argContext, NamespaceContext argNamespaceContext)
          Called by the SAXAdapter when a start tag, for which this callback interface has been registered, has been encountered.
 void setWriter(java.io.Writer argOut)
           
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XMLCallbackWriter

public XMLCallbackWriter()
Method Detail

setWriter

public void setWriter(java.io.Writer argOut)

onStartTag

public void onStartTag(java.lang.String argTagNamespace,
                       java.lang.String argLocalTagName,
                       java.lang.String argQName,
                       org.xml.sax.Attributes argAttributes,
                       java.lang.StringBuffer argText,
                       java.util.Map argContext,
                       NamespaceContext argNamespaceContext)
                throws org.xml.sax.SAXException
Description copied from interface: SAXTagHandler
Called by the SAXAdapter when a start tag, for which this callback interface has been registered, has been encountered.
Specified by:
onStartTag in interface SAXTagHandler
Following copied from interface: net.sourceforge.saxadapter.SAXTagHandler
Parameters:
argTagNamespace - namespace URI of tag
argLocalTagName - unqualified tag name
argQName - qualified name of tag
argAttributes - tag attributes
argText - a StringBuffer that contains the text between the start and end tags.
argContext - the Map that represents parsing context. This context must be understood by each handler
argNamespaceContext - an interface that allows the handler to access namespace data associated with the current parsing state
Throws:
org.xml.sax.SAXException -  

onEndTag

public void onEndTag(java.lang.String argTagNamespace,
                     java.lang.String argLocalTagName,
                     java.lang.String argQName,
                     java.util.Map argContext,
                     NamespaceContext argNamespaceContext)
              throws org.xml.sax.SAXException
Description copied from interface: SAXTagHandler
Called by the SAXAdapter when an end tag, for which this callback interface has been registered, has been encountered.
Specified by:
onEndTag in interface SAXTagHandler
Following copied from interface: net.sourceforge.saxadapter.SAXTagHandler
Parameters:
argTagNamespace - namespace URI of tag
argLocalTagName - unqualified tag name
argQName - qualified tag name
argContext - the Map that represents parsing context. This context must be understood by each handler
argNamespaceContext - an interface that allows the handler to access namespace data associated with the current parsing state
Throws:
org.xml.sax.SAXException -  

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 XMLCallbackWriter
Parameters:
args - the first and only argument is the path to an XML file in the classpath of the JVM