public
Description: A cute little query language for converting XML to Perl
Homepage: http://search.cpan.org/perldoc?XML::CuteQueries
Clone URL: git://github.com/jettero/xml--cutequeries.git
name age message
file .gitignore Sat Jul 25 07:20:32 -0700 2009 ignore this stuff (updates) [jettero]
file .perlcriticrc Fri Jul 03 03:59:48 -0700 2009 initial tests for CQ [jettero]
file .todo Mon Jul 13 13:39:27 -0700 2009 altered TODOs [jettero]
file Changes Loading commit data...
file CuteQueries.pm Fri Dec 18 05:12:10 -0800 2009 version up [jettero]
directory CuteQueries/ Sun Jul 05 14:53:12 -0700 2009 renamed module. No sense naming Twigx in the n... [jettero]
file MANIFEST Fri Dec 18 05:12:36 -0800 2009 forgot to manifest the new files [jettero]
file MANIFEST.SKIP Mon Jul 06 15:12:48 -0700 2009 dist desc [jettero]
file Makefile.PL Wed Oct 21 03:52:43 -0700 2009 avoid FAIL for missing data dumper [jettero]
file README Tue Jul 07 12:10:14 -0700 2009 make the README a more convincing example [jettero]
file bad.xml Wed Jul 29 04:06:37 -0700 2009 if you parse a bad xml, then try to parse a goo... [jettero]
directory contrib/ Wed Jul 29 03:56:47 -0700 2009 test things from the examples [jettero]
file ddo.xml
file example.xml Sun Jul 05 05:33:21 -0700 2009 talking about attr things we can't actually do ... [jettero]
file example2.xml Mon Jul 13 13:39:25 -0700 2009 this is an example of what I mean [jettero]
file example3.xml Sat Jul 25 07:36:26 -0700 2009 for my xml() type, and probably for use in the ... [jettero]
file example4.xml Mon Jul 27 05:35:27 -0700 2009 even harder [jettero]
directory lib/ Wed Jul 29 03:56:47 -0700 2009 more KAR examples [jettero]
directory t/
README
# This module produces results rather like L<XML::Simple>, but
# without the ambiguity problems inherent in going from XML to
# Perl.

use strict;
use warnings;
use XML::CuteQueries;

my $CQ = XML::CuteQueries->new;
   $CQ->parse(<<"EOXML");

<root>
    <result>OK</result>
    <data>
        <row><f1> 7</f1><f2>11</f2><f3>13</f3></row>
        <row><f1>17</f1><f2>19</f2><f3>23</f3></row>
        <row><f1>29</f1><f2>31</f2><f3>37</f3></row>
    </data>
</root>

EOXML

my $arrayref_of_hashrefs = $CQ->cute_query(
    # the top level query is for the <data> elements
    # the shape of the only top level query is [],
    # so it returns one [] -- for the one <data> element

    "data" => [

        # the contents of the top level [] is a sub query for row elements.
        # Each row element should be a hashref, so the data-[] will contain
        # three row-{} hashrefs

        row => {

            # the contents of those hashrefs is a subquery for any tag found
            # there.  The tag names are preserved as keys because we're
            # sitting in the context of a hashref.
            # the shape of each match result is '', so it just returns the
            # contents of each tag as a string.

            '*' => '',
        }
    ],
);

# [ {f1=> 7, f2=>11, f3=>13},
#   {f1=>17, f2=>19, f3=>23},
#   {f1=>29, f2=>31, f3=>37}, ]