apache > xerces > xerces-p
XML::Xerces
 

XML::Xerces Sample: DOM2Hash

Sample: DOM2Hash

DOM2Hash

DOM2Hash, illustrates how to traverse a DOM tree in memory and convert that tree to a simple recursive hash table data structure.

Running DOM2Hash

The DOM2Hash sample illustrates how convert a DOM tree to another format. To run DOM2Hash, enter the following

perl DOM2Hash.pl  <XML file>

Here is a sample output from DOM2Hash

perl DOM2Hash.pl roles.xml

$VAR1 = {
          'node_name' => 'contributors',
          'children' => [
                          {
                            'node_name' => 'person',
                            'attributes' => {
                                              'Role' => 'manager'
                                            }
                          }
                        ],
          'attributes' => {
                            'xmlns' => 'contributors'
                          }
        };