Release Info

Build Instructions

API Docs

DOM C++ Binding
Migration Guide

PDF Document

Source Repository
User Mail Archive
Devel Mail Archive


Xerces-C++ comes packaged with sample applications that demonstrate salient features of the parser using simple applications written on top of the SAX and DOM APIs provided by the parser. Sample XML data files are provided in the samples/data directory.

Building the Samples

For general information related to building--including platform-specific information--please refer to the Build Page. This information covers a standard installation where one has downloaded the entire Xerces-C binary distribution to a place on the filesystem to which one has write access. Below, we cover what to do if Xerces-C has been preinstalled on a system into a directory to which one does not have write access, but compiling the samples is desired.

In this situation, just do the following:

  1. Copy the entire contents of the samples directory into a directory named samples that you have write-access to;
  2. Set the XERCESCOUT environment variable to point to the directory that is the parent of the newly-created samples directory;
  3. Proceed as normal to compile the samples (not forgetting to set XERCESCROOT to point to the place on the file system where Xerces-C's include files etc. are to be found);

Once this is done, the compiled samples will be placed in a directory named bin; this directory will be located in the same directory as the samples directory created in step 1 above.

Running the Samples

The sample applications are dependent on the Xerces-C++ shared library (and could also depend on the ICU library if you built Xerces-C++ with ICU). Therefore, on Windows platforms you must make sure that your PATH environment variable is set properly to pick up these shared libraries at runtime.

On UNIX platforms you must ensure that LIBPATH environment variable is set properly to pick up the shared libraries at runtime. (UNIX gurus will understand here that LIBPATH actually translates to LD_LIBRARY_PATH on Solaris and Linux, SHLIB_PATH on HP-UX, DYLD_LIBRARY_PATH on Mac OS X, and stays as LIBPATH on AIX).

To set you LIBPATH (on AIX for example), you would type:

export LIBPATH=xerces-c2_7_0/lib:$LIBPATH

On both Windows and UNIX platforms, if the parser is built with icu message loader (like IBM XML4C binaries), or message catalog loader, then you need to set another environment variable, XERCESC_NLS_HOME to point to the directory, $XERCESCROOT/msg, where the message files reside.


Once you have set up the environment variables, you can run the samples by opening a command window (or your shell prompt for UNIX environments).

Xerces-C++ Samples
  • SAXCount
    SAXCount counts the elements, attributes, spaces and characters in an XML file.
  • SAXPrint
    SAXPrint parses an XML file and prints it out.
  • DOMCount
    DOMCount counts the elements in a XML file.
  • DOMPrint
    DOMPrint parses an XML file and prints it out.
  • MemParse
    MemParse parses XML in a memory buffer, outputing the number of elements and attributes.
  • Redirect
    Redirect redirects the input stream for external entities.
  • PParse
    PParse demonstrates progressive parsing.
  • StdInParse
    StdInParse demonstrates streaming XML data from standard input.
  • EnumVal
    EnumVal shows how to enumerate the markup decls in a DTD Grammar.
  • SEnumVal
    SEnumVal shows how to enumerate the markup decls in a Schema Grammar.
  • CreateDOMDocument
    CreateDOMDocument creates a DOM tree in memory from scratch.
  • SAX2Count
    SAX2Count counts the elements, attributes, spaces and characters in an XML file.
  • SAX2Print
    SAX2Print parses an XML file and prints it out.
  • PSVIWriter
    PSVIWriter exposes the underlying PSVI of the parsed XML file.
  • SCMPrint
    SCMPrint parses an XSD file and prints information about the Schema Component Model.

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