Duplicate Attribute

Discussion in 'Perl Misc' started by mittra@juno.com, Jul 6, 2012.

  1. Guest

    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.
    , Jul 6, 2012
    #1
    1. Advertising

  2. Klaus Guest

    On 7 juil, 00:38, 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::parsepp slurp_xml);
    use XML::Simple;
    use Data::Dumper;

    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'
    };
    ==========================================
    Klaus, Aug 4, 2012
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?QmlsbCBFbmRvdw==?=

    Duplicate BORDER attribute in WebControl.Table

    =?Utf-8?B?QmlsbCBFbmRvdw==?=, Jul 29, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    1,571
    =?Utf-8?B?QmlsbCBFbmRvdw==?=
    Jul 29, 2004
  2. tshad
    Replies:
    2
    Views:
    418
    tshad
    Apr 8, 2005
  3. Bostonasian
    Replies:
    1
    Views:
    807
    Joris Gillis
    Sep 18, 2005
  4. hummh
    Replies:
    0
    Views:
    330
    hummh
    Aug 9, 2007
  5. hummh
    Replies:
    0
    Views:
    161
    hummh
    Aug 9, 2007
Loading...

Share This Page