Novitiatus has asked for the wisdom of the Perl Monks concerning the following question:
I am doing so much better. I have one little problem. I have added attributes to my data. I'm using $product->print; below, but I really don't want to print the tags. I tried $product->text but it didn't like it. Thanks again, and this will really get me going for my real data. Patrick =====================xml===================== <company> <group> <name>dev group 1</name> <product platform='nt' >product 1</product> <product platform='sol' >product 2</product> <product platform='nt' >product 3</product> <product platform='HP' >product 4</product> </group> <group> <name>dev group 2</name> <product platform='nt' >product 1</product> <product platform='sol' >product 2</product> </group> </company> ===========end of xml================= #!/bin/perl -w use strict; use XML::Twig; my $field= 'group'; my $twig= new XML::Twig; $twig->parsefile( "company.xml"); # build the twig my $root= $twig->root; # get the root of the twig my @group = $root->children; # get the list foreach my $my_group (@group) # the sorted list { print "\nGroup Name: ",$my_group->first_child("name")->text; my $nb_product= $my_group->children( 'product'); print "\nNumber: $nb_product\n"; my $get_att = "platform"; my @products= $my_group->children( 'product'); foreach my $product (@products) { my $plat = $product->att($get_att); # get attribute print "Plat: $plat\n"; if ( "nt" eq $plat ) { print "NT: "; $product->print; # This prints tags } else { print "Unix: "; $product->print; # This prints tags } print "\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Another Simple XML::Twig question
by IOrdy (Friar) on Sep 22, 2001 at 06:05 UTC |