apache > xerces > xerces-p

XML::Xerces Sample: DOMPrint

Sample: DOMPrint


DOMPrint parses an XML file, constructs the DOM tree, and invokes DOMWriter::writeNode() to serialize the resultant DOM tree back to XML stream.

Running DOMPrint

The DOMPrint sample parses an XML file, using either a validating or non-validating DOM parser configuration, builds a DOM tree, and then invokes DOMWriter::writeNode() to serialize the resultant DOM tree. To run DOMPrint, enter the following:

perl DOMPrint.pl <XML file>

The following parameters may be set from the command line

 perl DOMPrint.pl [options] <XML file>

This program invokes the DOM parser, and builds the DOM tree
It then asks the DOMWriter to serialize the DOM tree.

    -e          create entity reference nodes. Default is no expansion.
    -v=xxx      Validation scheme [always | never | auto*].
    -n          Enable namespace processing. Default is off.
    -s          Enable schema processing. Default is off.

    -h          Show this help
  * = Default if not provided explicitly.

The parser has intrinsic support for the following encodings:\n"
    UTF-8, USASCII, ISO8859-1, UTF-16[BL]E, UCS-4[BL]E,\n"
    WINDOWS-1252, IBM1140, IBM037, IBM1047.\n"

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

cd samples
perl DOMPrint.pl -v=always personal.xml

<?xml version="1.0" encoding="iso-8859-1"?>

<!DOCTYPE personnel SYSTEM "personal.dtd">
<!-- @version: -->

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

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