Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

E4X4Perl ?

by Thilosophy (Curate)
on Dec 09, 2005 at 02:30 UTC ( [id://515439]=perlquestion: print w/replies, xml ) Need Help??

Thilosophy has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks,

I have just stumbled upon a blog entry about a technology that I had never heard of before, but that is apparently being widely implemented in the JavaScript world (Rhino 1.6 has it, Firefox 1.5 has it, Flash ActionScript 3 will have it): E4X -- ECMAScript for XML -- Native XML for JavaScript.

* var order = <order><customer>. . .</customer> <item><price>5</price><qty>10</qty></item> <item level="rush"> <price>2.5</price> <qty>30</qty> </item> <item level="rush"> <price>1.5</price> <qty>50</qty> </item> </order>; * var items = order.item; // XMLList of item el'ts * var prices = order..price; * var urgentItems = order.item.(@level == "rush"); * var itemAttrs = order.item[0].@*;

Basically E4X allows you to work with (and even embed) XML into JavaScript in a very straightforward fashion. In fact, the whole approach (especially the XML-here-doc/interpolation facility) strikes me as very Perlish, but a quick googling and a super-search here turned up nothing for "e4x perl".

My question is: are there plans to support E4X in Perl (not necessarily as a core feature, but as a module, and only as far is it is syntactically compatible), and is there already something similar to it in the Perl world.?

code sample taken from Brendan Eich's presentation at XTech 05

Replies are listed 'Best First'.
Re: E4X4Perl ?
by dragonchild (Archbishop) on Dec 09, 2005 at 04:04 UTC
    Write it yourself? Seriously, there's nothing preventing you from putting a module up on CPAN that does what you're talking about. Personally, this sounds very much like what the various XML-RPC modules (Frontier, RPC::XML, etc) do.

    As for syntax, you'd have to use $order->item and $order->ALL->price or something like that to make is legal Perl. Or, you could do what stvn has been doing in his P6 Object Metamodels, which would translate into E4X for Perl like:

    my $e4x_parser = E4X->new( ... ); my @items = $e4x->get( 'order.item' ); my @prices = $e4x->get( 'order..price'; );

    You get the idea.


    My criteria for good software:
    1. Does it work?
    2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?
Re: E4X4Perl ?
by Celada (Monk) on Dec 09, 2005 at 02:55 UTC

    The approach may be Perlish, but the syntax certainly isn't. I'd rather get all that spiffy functionality such as the double dot operator which I am guessing does a deep search but be able to write the data structure approximately like this instead:

    $order = [ order => [ customer => [ . . . ], item => [ price => 5, qty => 10, ], item => [ level => 'rush', price => 2.5, qty => 30, ], item => [ level => 'rush', price => 1.5, qty => 50, ], ], ];

    Of course what I'm really looking for here is something partway between a hash and an array which can store duplicate keys like an array but still access them in close to O(1) time.

    XML syntax is really ugly, IMHO, and "there's more than one way to do it" just like Perl but unlike Perl only one of them works so it's of no help. Grouping delimiters such as the parenthesis (and, by extension, others like [{<>}] were invented long ago and are still popular because they work best!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://515439]
Approved by holli
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-24 12:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found