Xerces Project

Release Info

Xerces-C++ 3.2.5
Build Instructions


API Reference
DOM C++ Binding
Migration Guide

Mailing Lists

Source Repository


SAXPrint uses the SAX 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.

Running SAXPrint

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

SAXPrint <XML file>

The following parameters may be set from the command line

    SAXPrint [options] <XML file>

This program invokes the SAX Parser, and then prints the
data returned by the various SAX handlers for the specified
XML file.

    -u=xxx      Handle unrepresentable chars [fail | rep | ref*].
    -v=xxx      Validation scheme [always | never | auto*].
    -n          Enable namespace processing.
    -s          Enable schema processing.
    -f          Enable full schema constraint checking.
    -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, US-ASCII, ISO8859-1, UTF-16[BL]E, UCS-4[BL]E,
    WINDOWS-1252, IBM1140, IBM037, IBM1047.

-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 or a schema declaration is present in the XML document

Here is a sample output from SAXPrint

cd xerces-c-3.2.5/samples/data
SAXPrint -v=always personal.xml

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

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

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

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

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

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

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

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

Copyright © 1999-2017 The Apache Software Foundation. All Rights Reserved.