Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Duplicate Attribute

Reply
Thread Tools

Duplicate Attribute

 
 
mittra@juno.com
Guest
Posts: n/a
 
      07-06-2012

I have an XML that looks like:

<abc attr1="val1" attr2="val2" attr1="val3">
</abc>

Yes, this is illegal per XML rule since we have two attr1 and when I parse it through XML::Simple, I get this error message:

duplicate attribute at line 14, column 291, byte 1936 at /usr/lib/perl5/XML/Parser.pm line 187

However, I am wondering if there is a way to tell XML::Simple to ignore this error.

Thanks.
 
Reply With Quote
 
 
 
 
Klaus
Guest
Posts: n/a
 
      08-04-2012
On 7 juil, 00:38, (E-Mail Removed) wrote:
> I have an XML that looks like:
>
> <abc attr1="val1" attr2="val2" attr1="val3">
> </abc>
>
> Yes, this is illegal per XML rule since we have two attr1 and when I parse it through XML::Simple, I get this error message:
>
> duplicate attribute at line 14, column 291, byte 1936 at /usr/lib/perl5/XML/Parser.pm line 187
>
> However, I am wondering if there is a way to tell XML::Simple to ignore this error.


Maybe XML::Reader (version 0.44) can help out:

==========================================
use strict;
use warnings;

use XML::Reader 0.44 qw(XML:arsepp slurp_xml);
use XML::Simple;
use Data:umper;

my $xml_with_dup =
q{<abc attr1='val1' attr2='val2' attr1='val3'></abc>};

my $xml_without_dup = slurp_xml(\$xml_with_dup,
{ dupatt => '|' },
{ root => '/', branch => '*' })->[0][0];

my $ref = XMLin($xml_without_dup);

print "With Dup = $xml_with_dup\n";
print "Without Dup = $xml_without_dup\n";
print Dumper($ref), "\n";
==========================================

This is the output:
==========================================
With Dup = <abc attr1='val1' attr2='val2' attr1='val3'></abc>
Without Dup = <abc attr1='val1|val3' attr2='val2'></abc>
$VAR1 = {
'attr2' => 'val2',
'attr1' => 'val1|val3'
};
==========================================
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to prevent duplicate title attribute in calendar control? hummh ASP .Net Web Controls 0 08-09-2007 04:55 PM
How to prevent duplicate title attribute in calendar control hummh ASP .Net 0 08-09-2007 10:31 AM
XSLT: Making attribute to parent attribute Bostonasian XML 1 09-18-2005 07:30 AM
Datagrid generating duplicate border attribute tshad ASP .Net 2 04-08-2005 06:09 PM
Duplicate BORDER attribute in WebControl.Table =?Utf-8?B?QmlsbCBFbmRvdw==?= ASP .Net 3 07-29-2004 04:45 PM



Advertisments