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

Home

Readme
Download

Build Instructions







Migration

Releases

Feedback

Y2K Compliance


CVS Repository
Mail Archive

Redirect
 

Redirect uses 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.

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


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

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

To delete all the generated object files and executables, type

gmake clean

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

Redirect is invoked as follows:

cd xml4c-3_5_1-linux/samples/data
Redirect personal.xml

The output is the following:

cd xml4c-3_5_1-linux/samples/data
Redirect personal.xml
personal.xml: 30 ms (37 elems, 12 attrs, 0 spaces, 268 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.



Footer