Redirect

Building Redirect

On Windows Platforms:

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

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.

SAXCount
SAXPrint
DOMCount
DOMPrint
Redirect
MemParse

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

where <platform> is the platform you are working on.This will create the object files in the <xml4c2InstallDir>/bin/obj/Redirect directory and the executable named Redirect in '<xml4c2InstallDir>/bin' directory. If the 'bin' or 'obj/Redirect' 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 Redirect

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

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

Running Redirect

This program illustrates how a XML application can use the SAX EntityResolver handler to redirect the input stream for external entities. It installs an entity resolver, traps the call to the external DTD file and redirects it to another specific file which contains the actual DTD.

The program then counts and reports the number of elements and attributes in the given XML file.

    Redirect [-v] <XML file>

The -v option is used to invoke the Validating SAX Parser instead.

When invoked as follows:

    cd <xml4c2InstallDir>/samples/data
    redirect -v personal.xml

The output is the following:

personal.xml: 30 ms (37 elems, 12 attrs, 134 spaces, 134 chars)

External files required to run this sample are 'personal.xml', 'personal.dtd' and 'redirect.dtd', which are all present in the 'samples/data' directory. Make sure that you run redirect in the samples/data directory.

The 'resolveEntity' callback in this sample looks for an external entity with system id as 'personal.dtd'. When it is asked to resolve this particular external entity, it creates and returns a new InputSource for the file 'redirect.dtd'.

A real-world XML application can similarly do application specific processing when encountering external entities. For example, an application might want to redirect all references to entities outside of its domain to local cached copies.

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