The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Spreadsheet::XLSX::Reader::LibXML::XMLToPerlData - Role to turn xlsx XML to perl hashes

SYNOPSIS

        #!/usr/bin/env perl
        use Data::Dumper;
        use     MooseX::ShortCut::BuildInstance qw( build_instance );
        use     Spreadsheet::XLSX::Reader::LibXML::XMLReader;
        use     Spreadsheet::XLSX::Reader::LibXML::Error;
        use     Spreadsheet::XLSX::Reader::LibXML::XMLToPerlData;
        my  $test_file = '../../../../test_files/xl/sharedStrings.xml';
        my  $test_instance      =       build_instance(
                        package => 'TestIntance',
                        superclasses =>[ 'Spreadsheet::XLSX::Reader::LibXML::XMLReader', ],
                        add_roles_in_sequence =>[ 'Spreadsheet::XLSX::Reader::LibXML::XMLToPerlData', ],
                        file => $test_file,
                        error_inst => Spreadsheet::XLSX::Reader::LibXML::Error->new,
                        add_attributes =>{
                                empty_return_type =>{
                                        reader => 'get_empty_return_type',
                                },
                        },
                );
        $test_instance->advance_element_position( 'si', 16 );# Go somewhere interesting
        print Dumper( $test_instance->parse_element ) . "\n";

        ###############################################
        # SYNOPSIS Screen Output
        # 01: $VAR1 = {
        # 02:           'list' => [
        # 03:                       {
        # 04:                         't' => {
        # 05:                                'raw_text' => 'He'
        # 06:                              }
        # 07:                       },
        # 08:                       {
        # 09:                         'rPr' => {
        # 10:                                  'color' => {
        # 11:                                             'rgb' => 'FFFF0000'
        # 12:                                           },
        # 13:                                  'sz' => '11',
        # 14:                                  'b' => 1,
        # 15:                                  'scheme' => 'minor',
        # 16:                                  'rFont' => 'Calibri',
        # 17:                                  'family' => '2'
        # 18:                                },
        # 19:                         't' => {
        # 20:                                'raw_text' => 'llo '
        # 21:                              }
        # 22:                       },
        # 23:                       {
        # 24:                         'rPr' => {
        # 25:                                  'color' => {
        # 26:                                             'rgb' => 'FF0070C0'
        # 27:                                           },
        # 28:                                  'sz' => '20',
        # 29:                                  'b' => 1,
        # 30:                                  'scheme' => 'minor',
        # 31:                                  'rFont' => 'Calibri',
        # 32:                                  'family' => '2'
        # 33:                                },
        # 34:                         't' => {
        # 35:                                'raw_text' => 'World'
        # 36:                              }
        # 37:                       }
        # 38:                     ]
        # 39:         };
        ###############################################
    

DESCRIPTION ############## Re-write XMLReader POD too!!!

This documentation is written to explain ways to use this module when writing your own excel parser. To use the general package for excel parsing out of the box please review the documentation for Workbooks, Worksheets, and Cells

This package is used convert xml to deep perl data structures. As a note deep perl xml and data structures are not one for one compatible to xml. However, there is a subset of xml that reasonably translates to deep perl structures. For this implementation node names are treated as hash keys unless there are multiple subnodes within a node that have the same name. In this case the subnode name is stripped and each node is added as a subref in an arrary ref. The overall arrayref is attached to the key list. Attributes are also treated as hash keys at the same level as the sub nodes. Text nodes (or raw text between base tags) is treated as having the key 'raw_text'.

This reader assumes that it is a role that can be added to a class built on Spreadsheet::XLSX::Reader::LibXML::XMLReader it expects to get the methods provided by that type of xml reader for traversing and reading the file. As a consequence it doesn't accept an xml object or file since it expects to access the method below.

Required Methods

Follow the links to see details of the current implementation.

Methods

These are the methods provided by this module.

parse_element( $level )

    Definition: This returns a deep perl data structure that represents the full xml down as many levels as indicated by $level (positive is deeper) or to the bottom for no passed value. When this method is done the xml reader will be left at the begining of the next xml node after the ending flag for the requested node.

    Accepts: $level ( a positive integer )

    Returns: ($success, $data_ref ) This method returns a list with the first element being success or failure and the second element being the data ref corresponding to the xml being parsed.

SUPPORT

TODO

    1. Nothing yet

AUTHOR

Jed Lund
jandrew@cpan.org

COPYRIGHT

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.

This software is copyrighted (c) 2014, 2015 by Jed Lund

DEPENDENCIES

SEE ALSO