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"; } }

In reply to Another Simple XML::Twig question by Novitiatus

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.