[Xml-compile] Re: XML::LibXML::Simple nil and restructuring

Joshua Keroes joshua at keroes.com
Tue Jun 18 15:31:15 GMT 2013


The XML::Compile list?


On Tue, Jun 18, 2013 at 12:46 AM, Mark Overmeer <mark at overmeer.net> wrote:

>
> 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> [q=
w/
> 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
> that
> > 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 array=
s.
> > 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/xml-compile/attachments/20130618/97=
e4b129/attachment.htm


More information about the Xml-compile mailing list