I not sure how more experienced Perl developers feel but in addition to XML::Parser, I found XML::SimpleObject a great way to start parsing XML. Here's a link:
http://www.xml.com/pub/a/2001/04/18/perlxmlqstart1.html Additionally, you can model the data anyway you want, but here's a little twist on what you have that may be worth pondering: <album> <artist>Alice in Chains</artist> <owner>Percy</owner> <category>Rock</category> </album> <album> <artist>The Pixies</artist> <owner>Percy</owner> <category>Rock</category> </album> <album> <artist>Percy and the Test Tube Babies</artist> <owner>Percy</owner> <category>Rock</category> </album> <album> <artist>Bob Marley</artist> <owner>Percy</owner> <category>Reggae</category> </album> <album> <artist>Peter Tosh</artist> <owner>Percy</owner> <category>Reggae</category> </album> <album> <artist>Percy Gone Jazz</artist> <owner>Percy</owner> <category>Reggae</category> </album> Yes Percy (owner) is repeated and so is the category, but it makes it a little easier to add another album to your file: <album> <artist>Napalm Death</artist> <owner>Joel</owner> <category>Ballads</category> </album> Hope this helps. Joel > -----Original Message----- > From: P0R0NG [mailto:[EMAIL PROTECTED]] > Sent: Friday, February 01, 2002 8:29 AM > To: [EMAIL PROTECTED] > Cc: Hanson, Robert > Subject: Re: PERL and XML Parser > > > oh yes thanks for that! thanks. i overlooked that. my big... > > anyways, here's the correct xml version: > > <? xml version="1.0" standalone="yes" ?> > <albums> > <owner>Percy</owner> > <category name ="rock"> > <artist>Alice in Chains</artist> > <artist>The Pixies</artist> > <artist>Percy and the Test Tube Babies</artist> > </category> > <category name = "reggae"> > <artist>Bob Marley</artist> > <artist>Peter Tosh</artist> > <artist>Percy Gone Jazz</artist> > </category> > </albums> > > in using xml parser, how can i get the content of element 'owner'? i > created the code but every content between the xml elements we parsed. > here's my code: > > #! /usr/local/bin/perl > > use XML::Parser; > my $parser = new XML::Parser (); > > $parser->setHandlers (Start => \&Start_handler, > End => \&End_handler, > Default => \&Default_handler > ); > > my $filename = shift; > die "Can't find '$filename': $!\n" unless -f $filename; > > $parser->parsefile ($filename); > > sub Start_handler { > my $p = shift; > my $el = shift; > > if ($el =~ m/owner/g) {print "<$el>"}; > } > > sub End_handler { > my ($p,$el) = @_; > if ($el =~ m/owner/g) { print "</$el>\n"; }; > } > > sub Default_handler { > my ($p,$str) = @_; > # my $p = shift; > # my $str = shift; > if (($str =~m/Percy/g) or ($str =~m/Percy/g)){ print "\n$str\n"; } > } > > On Fri, 1 Feb 2002 10:27:37 -0500 > "Hanson, Robert" <[EMAIL PROTECTED]> wrote: > > |By the way, there were a lot of XML errors in that example. > | > |<categories="rock"> > | > |You need an attribute name, this is not legal. > | > |<artist>Alice in Chains</rock> > | > |The closing tag does not match the opening tag. > | > |<categories = "reggae"> > | > |You need an attribute name, this is not legal. > | > |Rob > | > | > |-----Original Message----- > |From: P0R0NG [mailto:[EMAIL PROTECTED]] > |Sent: Friday, February 01, 2002 8:05 AM > |To: [EMAIL PROTECTED] > |Subject: PERL and XML Parser > | > | > |Hi list. > | > |I'm currently doing a perl project involving XML parser. > | > |given this xml snippet: > | > |<albums> > | <owner>Percy</owner> > | <categories="rock"> > | <artist>Alice in Chains</rock> > | <artist>The Pixies</artist> > | </categories> > | <categories = "reggae"> > | <artist>Bob Marley</artist> > | <artist>Peter Tosh</artist> > | </categories> > |</albums> > > _________________________________________________________ > Do You Yahoo!? > Get your free @yahoo.com address at http://mail.yahoo.com > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]