Running SAXWriter and DOMWriter

SAXWriter and DOMWriter are sample programs that can be used to invoke the parser on an XML document, and to print out the XML document on the console. By default, invoking SAXWriter will create a non-validating SAX parser, and will print out the XML in normal format.  The command lines below expect the current directory to be the directory containing the JAR file.

Source code:

 

To run SAXWriter with the default settings, use the following command line (all on one line):

    jre -cp xml4j.jar;xml4jSamples.jar
    sax.SAXWriter data\personal.xml

SAXWriter also allows you to change the default behavior via the following command line flags:

  • -p Specify the parser class to be used. The available parsers are:
              com.ibm.xml.parsers.SAXParser [default parser]
              com.ibm.xml.parsers.ValidatingSAXParser
  • -h Print SAXWriter help information. [default is no help]
  • -c Output in canonical format. [default is normal format]

Running SAXWriter with the default settings is equivalent to running SAXWriter like this (type this in as one long command line):

    jre -cp xml4j.jar;xml4jSamples.jar
        sax.SAXWriter
        -p com.ibm.xml.parsers.SAXParser
        data\personal.xml

 

To run DOMWriter with the default settings, use the following command line (all on one line):

    jre -cp xml4j.jar;xml4jSamples.jar
    dom.DOMWriter data\personal.xml

DOMWriter also allows you to change the default behavior via the following command line flags:

  • -p Specify the parser class to be used. The available parsers are:
              dom.wrappers.NonValidatingDOMParser
              dom.wrappers.DOMParser [default parser]
              dom.wrappers.TXParser
  • -h Print DOMWriter help information. [default is no help]
  • -c Output in canonical format. [default is normal format]

Running DOMWriter with the default settings is equivalent to running DOMWriter like this (type this in as one long command line):

    jre -cp xml4j.jar;xml4jSamples.jar
        dom.DOMWriter
        -p dom.wrappers.DOMParser
        data\personal.xml

Return to Samples