Hi

So, um, why not use those rules? Then work with the resulting hash?

*tip* ?node_id=3989;BIT=XML%3A%3ARules-%3Enew;HIT=xml ... Re: XML::LibXML drives me to drinking

This might be something like what you were attempting

#!/usr/bin/perl -- use strict; use warnings; use XML::Rules; use Data::Dump qw/ dd /; my $rawxml = q{<?xml version="1.0" encoding="UTF-8"?> <root> <summary> <item> <value>1.0</value> </item> </summary> <detail1> <item> <value>2.0</value> </item> </detail1> <detail2> <item> <value>3.0</value> </item> </detail2> <value> 11 </value> </root> }; dd( XML::Rules->new( rules => [], )->parse( $rawxml ) ); dd( XML::Rules->inferRulesFromExample( $rawxml ) ); dd( XML::Rules->new( rules => XML::Rules->inferRulesFromExample( $rawx +ml ), )->parse( $rawxml ) ); my ( $summary, $detail1, $detail2 ) ; my $xr = XML::Rules->new( qw/ stripspaces 8 /, rules => { 'detail1,detail2,item,root,summary' => sub { return; }, 'value' => [ '/root/summary/item' => sub { ( $summary, $detail1, $detail2 ) = (); #reset $summary = $_[1]->{_content}; return; }, '/root/detail1/item' => sub { $detail1 = $_[1]->{_content}; return; }, '/root/detail2/item' => sub { $detail2 = $_[1]->{_content}; warn "$summary $detail1 $detail1\n"; return; }, sub { die "unexpected 'value' at ".join('/','',@{$_[2]}) } +, ], }, ); my $ret = $xr->parse( $rawxml ); dd( $ret ); __END__ $ perl xml-rules-1205065.pl { root => { _content => "\n\n\n\n\n", detail1 => { _content => "\n \n", item => { _content => "\n \n ", value => { _cont +ent => "2.0" } }, }, detail2 => { _content => "\n \n", item => { _content => "\n \n ", value => { _cont +ent => "3.0" } }, }, summary => { _content => "\n \n", item => { _content => "\n \n ", value => { _cont +ent => "1.0" } }, }, value => { _content => " 11 " }, }, } { "detail1,detail2,item,root,summary" => "no content", "value" => "content", } { root => { detail1 => { item => { value => "2.0" } }, detail2 => { item => { value => "3.0" } }, summary => { item => { value => "1.0" } }, value => " 11 ", }, } 1.0 2.0 2.0 unexpected 'value' at /root at xml-rules-1205065.pl line 54.

In reply to Re^3: XML::Rules parsing inside out? by Anonymous Monk
in thread XML::Rules parsing inside out? by bfdi533

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.