Collecting multiple element names using grouptag

A

anthony

Hi, I have an XML file that I am reading and I am using XML::Simple to
do it.
Within the XML file there are certain root elements that contain
multiples of the same element name with different values.
I want to be able to collect these different values but have a
different delimiter other than the comma.
My example XML element is:
<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>

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],$_->{obsoletes}->[1]

You will notice that I am reading the first 2 obsolete element names -
but I think there is a better way to read them.

What I would like the file to look like is this:
MSS-020-01,112233-12,,L,sparc,SunOS,9,112961-01:113024-07:113030-02:113223-02:113275-02
etc. with no comma separating the obsolete values.

At the moment, the code above will produce:
MSS-020-01,112233-12,,L,sparc,SunOS,9,112961-01,113024-07 (2 obsolete
entries because I read first and second values only)
 
A

A. Sinan Unur

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__
 
U

usenet

anthony said:
Anybody can help on this please??

I saw your (original) question just after you posted it this morning.
The question was of some interest to me, since I use XML::Simple all
the time (decoding Odette ENGDAT files!) , and I'm pretty familiar with
the usage of this module. I was fully prepared to fire off a helpful
response, until I noticed that the question made it somewhat difficult
for me to do so.

The posting guidelines for this group can be found at
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html. They
recommend that you post a short, fully-functional Perl program which
illustrates your problem. That would make it very easy for me to
cut-and-paste your code into an editor, play around a bit, make any
revisions or enhancements that I felt would be helpful, and post the
revised code back to usenet.

But you didn't make it easy for me to help you - you made it difficult.
So I chose to ignore your question. I'm sure many others did likewise.
Nothing personal, you understand. It's just that when you ask good
questions and make it easy for folks to understand and reproduce your
situation, folks tend to be more willing to respond with prompt and
effective answers.

Something to keep in mind for the future...

Cheers!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,123
Latest member
Layne6498
Top