Running SAXWriter and DOMWriter

SAXWriter and DOMWriter parse your input file, and print it out again in XML format.  A command line option can be used to cause these samples to print in a "canonical" XML format, so they can be used to compare XML documents. SAXWriter and DOMWriter also display any errors or warnings that occurred during the parse. 

SAXWriter uses either the validating or non-validating SAX parser. DOMWriter uses either the validating or non-validating DOM parser.

DOMWriter provides a feature to set the output Java encoding through the -e switch.

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]
  • -e encodingName Output using the specified encoding. [default is UTF8]

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
        -e UTF8
        data\personal.xml

Running DOMWriter with the -e switch and no encoding specified will print out a list of valid encoding names (type this in as one long command line):

    jre -cp xml4j.jar;xml4jSamples.jar
        dom.DOMWriter
        -e

Prints the following:

Java Encoding one of( case sensitive ):
  Default
  8859_1 8859_2 8859_3 8859_4 8859_5 8859_6 8859_7
  8859_8 8859_9 Cp037 Cp273 Cp277 Cp278 Cp280
  Cp284 Cp285 Cp297 Cp420 Cp424 Cp437 Cp500
  Cp737 Cp775 Cp838 Cp850 Cp852 Cp855 Cp856
  Cp857 Cp860 Cp861 Cp862 Cp863 Cp864 Cp865
  Cp866 Cp868 Cp869 Cp870 Cp871 Cp874 Cp875
  Cp918 Cp921 Cp922 Cp930 Cp933 Cp935 Cp937
  Cp939 Cp942 Cp948 Cp949 Cp950 Cp964 Cp970
  Cp1006 Cp1025 Cp1026 Cp1046 Cp1097 Cp1098 Cp1112
  Cp1122 Cp1123 Cp1124 Cp1250 Cp1251 Cp1252 Cp1253
  Cp1254 Cp1255 Cp1256 Cp1257 Cp1258 Cp1381 Cp1383
  Cp33722 MS874 DBCS_ASCII DBCS_EBCDIC EUC EUCJIS GB2312
  GBK ISO2022CN_CNS ISO2022CN_GB JIS JIS0208 KOI8_R KSC5601
  MS874 SJIS SingleByte Big5 CNS11643 MacArabic
  MacCentralEurope MacCroatian MacCyrillic MacDingbat
  MacGreek MacHebrew MacIceland MacRoman MacRomania
  MacSymbol MacThai MacTurkish MacUkraine SJIS Unicode
  UnicodeBig UnicodeLittle UTF8

Return to Samples