Christopher Berning

NAME

        DBIx::XML::DataLoader::XMLWriter

SYNOPSIS

        use DBIx::XML::DataLoader::XMLWriter;

        my $doc=DBIx::XML::DataLoader::XMLWriter->makexml(\%all_data, $doc_root);
or
        use DBIx::XML::DataLoader::XMLWriter;

        my $w=DBIx::XML::DataLoader::XMLWriter->new();
        my $doc=$w->makexml(\%all_data, $doc_root);

DESCRIPTION

        XMLWriter is packaged as part of the DBIx::XML::DataLoader module.
        XMLWriter.pm will take a referance to a data structure and
        output xml based upon the contents of the referanced data.
        

SIMPLE EXAMPLE

        The data sent to XMLWriter needs to be in the following structure.
        XMLWriter expects to get hash referance to a hash that contains
        a hash keyed to table names, with each table key's value is a hash
        containing a data hash and keys for (parent, xpath, and node);
        
        The data hash will contain all data for a given segment of xml.
        The hash is keyed by numbers that are based on the number of iterations
        of data contained in the hash. Each number key points to a array of hash which
        contain the actual data, item_node, xpath, and a attribute. Only the attribute node is
        optional.

SAMPLE CODE

        use DBIx::XML::DataLoader::XMLWriter;

        $rootnode="docroot";
        %sample=(
        xml_a=>(
                data=>(
                1=>[{
                        val='hello',
                        item_node='first',
                        xpath=>'./message',
                        attribute=>undef
                   },

                {
                        val='world',
                        item_node='second',
                        xpath=>'./message',
                        attribute=>undef
                   }],
        parent=> undef,
        xpath=>'./welcome/message',
        node=>'welcome'
        );

        print  DBIx::XML::DataLoader::XMLWriter->makexml(\%sample, $doc_root);
or
        use DBIx::XML::DataLoader::XMLWriter;
        
        my $w=DBIx::XML::DataLoader::XMLWriter->new();
        $rootnode="docroot";
        %sample=(
        xml_a=>(
                data=>(
                1=>[{
                        val='hello',
                        item_node='first',
                        xpath=>'./message',
                        attribute=>undef
                   },

                {
                        val='world',
                        item_node='second',
                        xpath=>'./message',
                        attribute=>undef
                   }],
        parent=> undef,
        xpath=>'./welcome/message',
        node=>'welcome'
        );

        print  $w->makexml(\%sample, $doc_root);

The results would be

        <?xml version='1.0' standalone='yes'?>
        <!-- document created using XMLWriter 1.0 at Time 11:11:00 Date 11/20/2002 -->
        <docroot>
          <welcome>
            <message>
              <first>hello</first>
              <second>world</second>
            </message>
          </welcome>
        </docroot>

MORE COMPLEX SAMPLE CODE

        use DBIx::XML::DataLoader::XMLWriter;

        $rootnode="family_tree";
        %sample=(
                xml_a=>{
                        data=>{
                        1=>[{
                        val=>'Tom',
                        xpath=>'./first',
                        item_node=>'first',
                        attribute=>undef
                        },

                        {
                        val=>'brother',
                        xpath=>'./type',
                        item_node=>'type',
                        attribute=>undef
                        },
                                                {
                        val=>'Ann',
                        xpath=>'parent::maternal/@mother',
                        node=>'parent::maternal',
                        attribute=>'mother'
                        }],
                        
                        2=>[{
                        val=>'Chris',
                        xpath=>'./first',
                        item_node=>'first',
                        attribute=>undef
                        },

                        {
                        val=>'brother',
                        xpath=>'./type',
                        item_node=>'type',
                        attribute=>undef
                        },
                        {
                        val=>'Ann',
                        xpath=>'parent::maternal/@mother',
                        item_node=>'parent::maternal',
                        attribute=>'mother'
                        }
                        ]},
                parent=> 'mother',
                xpath=>'./family/maternal/sybling',
                node=>'sybling'},

                mother=>{
                        data=>{
                        1=>[{
                        val=>'Ann',
                        xpath=>'./maternal/@mother',
                        item_node=>'maternal',
                        attribute=>'mother'
                        },

                        {
                        val=>'Shumm',
                        xpath=>'./maternal/@maiden',
                        item_node=>'maternal',
                        attribute=>'maiden'
                        }]},
                parent=> undef,
                xpath=>'./family',
                node=>'family'}

        );

        $xmlref=\%sample;
        print  DBIx::XML::DataLoader::XMLWriter->makexml($xmlref, $rootnode);

The results would be

        <?xml version='1.0' standalone='yes'?>
        <!-- document created using XMLWriter at Time 11:14:50 Date 11/22/2002 -->
        <family_tree>
          <family>
            <maternal mother="Ann" maiden="Shumm">
              <sybling>
                <first>Tom</first>
                <type>brother</type>
              </sybling>
              <sybling>
                <first>Chris</first>
                <type>brother</type>
              </sybling>
            </maternal>
          </family>
        </family_tree>

Also see man page for

               DBIx::XML::DataLoader::XMLWriterDBIx::XML::DataLoader::MapIt,  and  DBIx::XML::DataLoader::DB