Re: Collecting multiple element names using grouptag
- From: "A. Sinan Unur" <1usa@xxxxxxxxxxxxxxxxxxx>
- Date: Tue, 20 Dec 2005 00:14:51 GMT
"anthony" <anthony@xxxxxxxxxxxxxxxxx> wrote in
news:1135010940.948034.199570@xxxxxxxxxxxxxxxxxxxxxxxxxxxx:
> Hi, I have an XML file that I am reading and I am using XML::Simple to
> do it.
....
> My code that reads this file :
> my $struct = $simple->XMLin($xmlcontent, forcearray => 1, keeproot =>
> 1, noattr => 1, SuppressEmpty => 1, GroupTags => { osver =>
> 'obsoletes' } );
> print FILE <<EOF;
> $_->{ibmid}->[0],$_->{vendorid}->[0],$num,$_->{severity}->[0],$_->
{arch
> }->[0],$_->{os}->[0],$_->{osver}->[0],$_->{obsoletes}->[0],$_->
{obsolet
> es}->[1]
>
> You will notice that I am reading the first 2 obsolete element names -
We don't care. What we care about is code that we can copy and past to
compile and run with minimal effort. Elsthread, you are complaining that
no one has answered your question, but you don't realize that you have
to put some effort into posting readable and compilable code. Please
read the posting guidelines for this group.
#!/usr/bin/perl
use strict;
use warnings;
use XML::Simple;
my $xml = <<EO_XML;
<record id="2823" action="add">
<id>MSS-020-01</id>
<vendorid>112233-12</vendorid>
<date>2004-04-23</date>
<severity>L</severity>
<arch>sparc</arch>
<os>SunOS</os>
<osver>9</osver>
<obsoletes>112961-01</obsoletes>
<obsoletes>113024-07</obsoletes>
<obsoletes>113030-02</obsoletes>
<obsoletes>113223-02</obsoletes>
<obsoletes>113275-02</obsoletes>
<obsoletes>113361-08</obsoletes>
<obsoletes>113454-14</obsoletes>
<obsoletes>113538-11</obsoletes>
<obsoletes>113577-01</obsoletes>
<obsoletes>114359-02</obsoletes>
<obsoletes>114385-03</obsoletes>
<obsoletes>114393-02</obsoletes>
<obsoletes>114394-02</obsoletes>
<obsoletes>115169-01</obsoletes>
<desc>Sun Security Vulnerability With the Extended Library Function
sendfilev(3EXT)</desc>
</record>
EO_XML
my $struct = XMLin($xml,
forcearray => 1,
keeproot => 1,
noattr => 1,
SuppressEmpty => 1,
GroupTags => {
osver => 'obsoletes',
}
);
print join(
',', $struct->{record}->[0]->{id}->[0],
$struct->{record}->[0]->{vendorid}->[0],
$struct->{record}->[0]->{severity}->[0],
$struct->{record}->[0]->{arch}->[0],
$struct->{record}->[0]->{os}->[0],
$struct->{record}->[0]->{osver}->[0],
join(':', @{ $struct->{record}->[0]->{obsoletes} }),
), "\n";
__END__
--
A. Sinan Unur <1usa@xxxxxxxxxxxxxxxxxxx>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
.
- References:
- Collecting multiple element names using grouptag
- From: anthony
- Collecting multiple element names using grouptag
- Prev by Date: Re: "Close match" regex
- Next by Date: Re: Bit-Vector-6.4 on Cygwin
- Previous by thread: Re: Collecting multiple element names using grouptag
- Next by thread: FAQ 4.21 How do I remove consecutive pairs of characters?
- Index(es):
Relevant Pages
|