www.alphaworks.ibm.comwww.ibm.com/developerwww.ibm.com

Home

Readme
Download

Build Instructions







Migration

Releases

Feedback

Y2K Compliance


CVS Repository
Mail Archive

SAX2Print
 

SAX2Print uses the SAX2 APIs to parse an XML file and print it back. Do note that the output of this sample is not exactly the same as the input (in terms of whitespaces, first line), but the output has the same information content as the input.

Building on Windows
 

Load the xml4c-3_5_1-win32\samples\Projects\Win32\VC6\samples.dsw Microsoft Visual C++ workspace inside your MSVC IDE. Then build the project marked SAX2Print.


Building on UNIX
 
cd xml4c-3_5_1-linux/samples
./runConfigure -p<platform> -c<C_compiler> -x<C++_compiler>
cd SAX2Print
gmake

This will create the object files in the current directory and the executable named SAX2Print in 'xml4c-3_5_1-linux/bin' directory.

To delete all the generated object files and executables, type

gmake clean

Running SAX2Print
 

The SAX2Print sample parses an XML file and prints out the contents again in XML (some loss occurs). To run SAX2Print, enter the following

SAX2Print <XML file>

The following parameters may be set from the command line

Usage: SAX2Print [options] file
This program prints the data returned by the various SAX2
handlers for the specified input file. Options are NOT case
sensitive.

Options:
    -u=xxx      Handle unrepresentable chars [fail | rep | ref*]
    -v=xxx      Validation scheme [always | never | auto*]
    -e          Expand Namespace Alias with URI's.
    -x=XXX      Use a particular encoding for output (LATIN1*).
    -?          Show this help

  * = Default if not provided explicitly

The parser has intrinsic support for the following encodings:
    UTF-8, USASCII, ISO8859-1, UTF-16[BL]E, UCS-4[BL]E,
    WINDOWS-1252, IBM1140, IBM037

-u=fail will fail when unrepresentable characters are encountered
-u=rep will replace with the substitution character for that codepage
-u=ref will report the character as a reference

-v=always will force validation
-v=never will not use any validation
-v=auto will validate if a DOCTYPE declaration is present in the XML document

Here is a sample output from SAX2Print

cd xml4c-3_5_1-linux/samples/data
SAX2Print -v=always personal.xml

<?xml version="1.0" encoding="LATIN1"?>
<personnel>

  <person id="Big.Boss">
    <name><family>Boss</family> <given>Big</given></name>
    <email>chief@foo.com</email>
    <link subordinates="one.worker two.worker three.worker
	                       four.worker five.worker"></link>
  </person>

  <person id="one.worker">
    <name><family>Worker</family> <given>One</given></name>
    <email>one@foo.com</email>
    <link manager="Big.Boss"></link>
  </person>

  <person id="two.worker">
    <name><family>Worker</family> <given>Two</given></name>
    <email>two@foo.com</email>
    <link manager="Big.Boss"></link>
  </person>

  <person id="three.worker">
    <name><family>Worker</family> <given>Three</given></name>
    <email>three@foo.com</email>
    <link manager="Big.Boss"></link>
  </person>

  <person id="four.worker">
    <name><family>Worker</family> <given>Four</given></name>
    <email>four@foo.com</email>
    <link manager="Big.Boss"></link>
  </person>

  <person id="five.worker">
    <name><family>Worker</family> <given>Five</given></name>
    <email>five@foo.com</email>
    <link manager="Big.Boss"></link>
  </person>

</personnel>
SAX2Print does not reproduce the original XML file. SAX2Print and DOMPrint produce different results because of the way the two APIs store data and capture events.


Footer