Yea, same guy. Had problems at home with other user then use bizza user.

Belows what I've done. Firstly, I found out that the inner elements <ID> are processed before the outer ones <AC>. With the twig_handlers, all of them are being processed eventhough, for e.g you only want a listing of <AC>'s. I think I'll have if stmts to check what the users requesting.

The tutorial is too lightweight, xml examples doesn't really deal or include examples attribute checking/extraction. Actually, the xml file used(nba.xml)to simple, hence the simple examples.

Also some XML::XPath usage would be great. This doesn't come thru' even in the developer version document. I think the tutorial should include a comprehensive xml file with attributes. I should show how extract and/or update specific elements (attribs and tags), how to find specific nodes, delete, modify and update em, traverse the doc. Because of the myriad of methods, classes and/or options available to perform a function - in maybe both "normal twiggy way" and xpath way.

There's a lotta things to say, however that's one for another topic. The way it is, to pick XML::Twig is really difficult

Bizza(thandi)

HERE're my attempts at getting to know and understand: #!/usr/bin/perl use strict; use warnings; use XML::Twig; # perl test_thandi CCC '@n=AAA' # perl test_thandi CCC '@n="AAA" or @set="y"' my( $ac_n_value, $ai_att_cond)= @ARGV; XML::Twig->new( TwigHandlers => { # qq{AC[\@n="$ac_n_value"]/AI[$ai_att_cond]} => \&print_ai_data }, # qq{AC[\@n="$ac_n_value"]/AI[$ai_att_cond]/ID[\@n=$id_att_cond]} => + \&print_id_data }, # ID => \&id_print , #list all IDs desc <desc> </desc> # AI => \&ai_print , qq{AC} => \&ac_print, #list all ACs <desc> </desc> qq{AC/AI} => \&ai_print, #list all AIs <desc> </desc> }, pretty_print => 'indented', # keep_atts_order => 1, # do_not_chain_handlers => 1 ) ->parsefile( "custs.xml"); sub ac_print { my( $t, $ac)= @_; my $Desc = $ac->first_child('Desc')->text; print "AC DESC: $Desc\n"; print "=======================================\n"; } sub ai_print { my( $t, $ai)= @_; my $Desc = $ai->first_child('Desc')->text; print "AI DESC: $Desc\n"; print "----------------------------------\n"; } sub id_print { my( $t, $id)= @_; my $Desc = $id->first_child('Desc')->text; my $What = $id->first_child('What')->text; my $AR = $id->first_child('AR')->text; print "--> DESC: $Desc\n"; print "What: $What\n"; print "AR: $AR\n"; }

In reply to Re^6: XML::Twig question by thandi
in thread XML::Twig question by thandi

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.