in reply to Re^5: XML::Twig question
in thread XML::Twig question
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 difficultBizza(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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: XML::Twig question
by mirod (Canon) on Dec 20, 2006 at 13:35 UTC | |
by thandi (Novice) on Dec 20, 2006 at 14:33 UTC |