Fwd: [Xml-compile] Re: XML::LibXML::Simple nil and restructuring
Joshua Keroes
joshua at keroes.com
Wed Jun 19 16:29:27 GMT 2013
Forwarding this on to the group!
---------- Forwarded message ----------
From: Mark Overmeer <mark at overmeer.net>
Date: Tue, Jun 18, 2013 at 12:45 AM
Subject: [Xml-compile] Re: XML::LibXML::Simple nil and restructuring
To: Joshua Keroes <joshua at keroes.com>
Hi Joshua,
Please post to the list.
* Joshua Keroes (joshua at keroes.com) [130617 23:15]:
> I'm proxying requests to an unhelpful API, trying to make lookups easier
> (done), and trying to "fix" their XML (done with XML::LibXML::Simple and
> Data::Visitor but slow), and returning the response to the user.
> With options *keyattr =3D> [qw/ name description /], forcearray =3D> [qw/=
rows
> r c /]*, X::L::S converts that to:
>
> * 'rows' =3D> [*
> * {*
> * 'r' =3D> [*
> * {*
> * 'c' =3D> [*
> * {*
> * 'xsi:nil' =3D> 'true',*
> * 'xmlns:xsi' =3D> '
http://www.w3.org/2001/XMLSchema-instance
> '*
> * },*
...
> * ],*
> * 'properties' =3D> {*
> * 'property' =3D> {*
> * 'type' =3D> 'int',*
> * 'content' =3D> '0',*
> * 'name' =3D> 'healthIndex'*
> * }*
> * },*
> * 'cellproperties' =3D> {}*
> * }*
> * ]*
> * }*
> * ]*
>
> Thing 1: I would like to see *undef* instead of* { 'xsi:nil' ... }*
blocks.
> e.g. *c =3D> [ undef, undef, undef ] . *I have a Data::Visitor solution t=
hat
> can do this but it's slow.
XML::LibXML::Simple is just a reimplementation of the XML::Simple
interface using the XML::LibXML parser. It is not more clever.
> Thing 2: *r* and *c* are just arrays. They don't need to be named arrays.
> Did I miss a way to eat those keys? In other words, what I'd like to see
is:
>
> * rows =3D> [*
> * [ undef, undef, undef ],*
> * ]*
> *
> And for responses with more complex data:
>
> * rows =3D> [*
> * [ 1.0, 2.2, 4.1 ],*
> * [ 1.0, 2.1, 4.0 ],*
> * [ 1.0, 2.2, 4.1 ],*
> * ]*
When the data structure is so well known, it is easy to avoid the use
of Data::Visitor. Something like this (untested)
my $rows =3D ....
my @r;
foreach my $r (@{$rows->[0]{r}})
{ my @c;
foreach my $c (@{$r->[0]{c}})
{ push @c, ref $c eq 'HASH' && $c->{'xsi:nil'} ? undef : $c;
}
push @r, \@c;
}
\@r;
Not more complex than this. (You loose the 'properties' info')
--
Regards,
MarkOv
------------------------------------------------------------------------
Mark Overmeer MSc MARKOV Solutions
Mark at Overmeer.net solutions at overmeer.net
http://Mark.Overmeer.net http://solutions.overmeer.net
_______________________________________________
Xml-compile mailing list
Xml-compile at lists.scsys.co.uk
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/xml-compile
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/xml-compile/attachments/20130619/c2=
25eab6/attachment.htm
More information about the Xml-compile
mailing list