Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: •Re: XML::Parser and Invalid XML

by Flame (Deacon)
on Jul 17, 2002 at 22:46 UTC ( #182625=note: print w/replies, xml ) Need Help??

in reply to •Re: XML::Parser and Invalid XML
in thread XML::Parser and Invalid XML

As I said, I know it's breaking the rules, so it's technically not W3C XML, but it's what XML::Simple end's up outputting and calling XML, so I don't know what to do about it.

I have a data structure like this:
{ 'uid' => { '1' => ['3','4','5','6'], '2' => ['4','3','1','5'], }, 'did' => { '1' => '2', '3' => ['1','2'], '4' => ['1','2'], '5' => ['1','2'], '6' => '1', }, }

When I run XMLout() from XML::Simple on that structure, I get:
<opt> <did 1="2" 6="1"> <3>1</3> <3>2</3> <4>1</4> <4>2</4> <5>1</5> <5>2</5> </did> <uid> <1>3</1> <1>4</1> <1>5</1> <1>6</1> <2>4</2> <2>3</2> <2>1</2> <2>5</2> </uid> </opt>

So how can I fix it? I'm open to just about anything here including alternative storage systems, but XMLin() won't read what XMLout() outputs. Is there a way to trick XML::Parser (or expat or whatever it's called) into thinking <1>234</1> is valid?

"Weird things happen, get used to it."

Flame ~ Lead Programmer: GMS

Replies are listed 'Best First'.
Re: Re: &bull;Re: XML::Parser and Invalid XML
by mirod (Canon) on Jul 17, 2002 at 23:03 UTC

    I think you are using the wrong tool here. If you really want to dump this structure as XML you could use Data::DumpXML (and its friend Data::DumpXML::Parser).

    The Error Message is GOD - MJD

      This looks like it'll do the trick. Thanks!

      "Weird things happen, get used to it."

      Flame ~ Lead Programmer: GMS

Re: Re: &bull;Re: XML::Parser and Invalid XML
by runrig (Abbot) on Jul 17, 2002 at 23:02 UTC
    This could be better, but you get the idea, just copy the hash with a tacked on token to all the hash keys.
    my %hash = qw(1 a 2 b 3 c); my $fixed_href = {}; fix_hash(\%fix_hash, $fixed_href); sub fix_hash { my ($old, $new) = @_; while (my ($key, $value) = each %$old) { (my $nkey = $key) =~ s/^(?=\d)/N/; if (ref($value) eq 'HASH') { $new_value = {}; $new->{$nkey} = $new_value; fix_hash($value, $new_value; } else { $new->{$nkey} = $value; } } }

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://182625]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2021-09-16 12:08 GMT
Find Nodes?
    Voting Booth?

    No recent polls found