SAXPrint

Building SAXPrint

On Windows Platforms:

Load the <xml4c2InstallDir>\samples\Projects\Win32\VC6\samples.d sw Microsoft Visual C++ workspace inside your MSVC IDE. Then build the project marked SAXPrint.

On UNIX (AIX, Solaris, HP-UX, Linux):

Make sure you have set your environment variable ROOTDIR to point to the top-most directory where you installed XML4C.

cd <xml4c2InstallDir>/samples/Projects/ <platform>
make -f SAXPrint.mak COMPILESWITCH="-w -O"

where <platform> is the platform you are working on.This will create the object files in the <xml4c2InstallDir>/bin/obj/SAXPrint directory and the executable named SAXPrint in '<xml4c2InstallDir>/bin' directory. If the 'bin' or 'obj/SAXPrint' directories do not exist then the build will fail. In that case you need to create the missing directory(s) under '<xml4c2InstallDir>' directory.

To delete the object and executable files of SAXPrint, type:

    cd <xml4c2InstallDir>/samples/Projects/<platform>
    make clean -f SAXPrint.mak

This would delete all the object files (.o files) from your 'obj/SAXPrint' sample directory and the executable from '<xml4c2InstallDir>/bin' directory.

Running SAXPrint

The SAXPrint sample parses an XML file and then prints it out. To run SAXPrint, enter the following:

    saxprint <filename>

To use the validating parser, use

    saxprint -v <filename>

SAXPrint has some limitations due to the SAX API. It will not display parts of the XML document which do not have a corresponding callback in the SAX API. It doesn't display the <?XML ... ?> prologue line (this means that it cannot process its own output). It will not display comments. In addition, it will expand abbreviated empty tags like <tagname/> into a matching <tagname> </tagname> pair.

Here is some sample output for SAXPrint

    cd <xml4c2InstallDir>/samples/data
    saxprint personal.xml

The output should be:

<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>
 

Note that SAXPrint does not reproduce the original XML file. Also SAXPrint and DOMPrint produce different results because of the way the two APIs store data and capture events.

Copyright (c) IBM Corp. 1999, Center for Java Technology , Cupertino, USA