Re: Collecting multiple element names using grouptag



"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
.



Relevant Pages

  • Re: What makes VB.Net XslTransform REALLY REALLY SLOW?
    ... > situations with heavy dependency on the xsl:key function. ... Thanks - I cam across the xsl:key references on google. ... next/previous/child/parent (i.e. reading databases)- but is slow beyond ... The only thing I am using .Net for is reading a large XML file and ...
    (microsoft.public.dotnet.framework.performance)
  • Re: Read XML value
    ... Chris, I'd suggest you can use the XSD.EXE tool that comes with the .net ... You can edit the schema to make sure it is what you want. ... > Below is an XML file I have been given. ... > just cannot work out the code for reading a value. ...
    (microsoft.public.dotnet.general)
  • Using static library
    ... I needed a library for reading ... the configuration from an xml file. ... then we rebuilt the static library after ...
    (microsoft.public.vc.language)
  • Exception thrown outside debugger but not in debugger
    ... I am reading and writing xml files via ... XmlDocument and XmlTextWriter. ... outside the debugger I receive the following error: ... Creating xml file ...
    (microsoft.public.dotnet.languages.csharp)
  • Xml validation exception only occurs outside debugger - VS 2003 C#
    ... I am reading and writing xml files via ... XmlDocument and XmlTextWriter. ... outside the debugger I receive the following error: ... Creating xml file ...
    (microsoft.public.dotnet.xml)