SAX/DOMWriter Samples

| Running SAXWriter and DOMWriter |
| `SAXWriter` and `DOMWriter` parse your input file, and print it out in XML format. A command line option can be used to print in a "canonical" XML format so the output can be used to compare XML documents. SAXWriter and DOMWriter also display any errors or warnings that occurred during the parse. `DOMWriter` provides a -e switch to set the output Java encoding. The command lines below expect the current directory to be the directory containing the JAR file. Requirements: Xerces-J is loaded on your computer. JDK is loaded on your computer. Source code: SAXWriter.java DOMWriter.java
| SAXWriter |
| To run SAXWriter: open up a MS-DOS command line window set the path to the jdk\bin directory change directory to the latest xerces-1_4_4 directory invoke the `SAXWriter` sample On Windows: The easiest way to do this is to create a .bat file using the Notepad editor. Then the `SAXWriter` can be invoked by double clicking on the file name or icon. The following command lines assume that both the jdk and the xerces-1_4_4 directories are located directly below the c: drive.
    set PATH=%PATH%;c:\jdk1.1.8\bin
    set CLASSPATH=%CLASSPATH%;c:\xerces-1_4_4\xerces.jar;c:\xerces-1_4_4\xercesSamples.jar
    cd c:\xerces-1_4_4
    java sax.SAXWriter data/personal.xml
Switches: SAXCount also allows you to change the default behavior using the following command line flags: -p Specify the parser class to be used. The available parsers are: org.apache.xerces.parsers.SAXParser [default parser] -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):
    java sax.SAXWriter -p org.apache.xerces.parsers.SAXParser
        data/personal.xml
Bringing up the help information:
    java sax.SAXWriter -h
Print in canonical format:
    java sax.SAXWriter -c  data/personal.xml
| Parse your own XML file instead of data/personal.xml
| DOMWriter |
| To run DOMWriter: open up a MS-DOS command line window set the path to the jdk\bin directory change directory to the latest xerces-1_4_4 directory invoke the `DOMWriter` sample On Windows: The easiest way to do this is to create a .bat file using the Notepad editor. Then the `DOMWriter` can be invoked by double clicking on the file name or icon. The following command lines assume that both the jdk and the xerces-1_4_4 directories are located directly below the c: dirve.
    set PATH=%PATH%;c:\jdk1.1.8\bin
    set CLASSPATH=%CLASSPATH%;c:\xerces-1_4_4\xerces.jar;c:\xerces-1_4_4\xercesSamples.jar
    cd c:\xerces-1_4_4
    java dom.DOMWriter data/personal.xml
Switches: DOMCount also allows you to change the default behavior via the following command line flags (type this in as one long command line): -p Specify the parser class to be used. The available parsers are: dom.wrappers.DOMParser [default parser] -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:
    java dom.DOMWriter -p dom.wrappers.DOMParser
        data/personal.xml
Bringing up the help information:
    java dom.DOMWriter -h
Searching for elements:
    java dom.DOMWriter -c data/personal.xml
Running DOMWriter with the -e switch and no encoding specified will print out a list of valid encoding names:
    java 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
| Parse your own XML file instead of data/personal.xml

Copyright © 1999, 2000 The Apache Software Foundation. All Rights Reserved.