[XQuery Talk Mailing List Archive Home] [By Date] [By Thread] [By Subject] [By Author] [Recent Entries] [Reply To This Message]

ANSWERS to "What's wrong with XQuery" question

Brett Zamir brettz9 at yahoo.com
Mon Jul 26 18:53:48 PDT 2010

  ANSWERS to "What's wrong with XQuery" question
  On 7/26/2010 5:18 PM, James Fuller wrote:
> Thx to Martin for the succinct overview of issues with XML<->JSON,
> I guess I am more leaning towards coming up with 'something different'
> ... maybe look at what serializing/dumping e4x internal representation
> is as I am assuming its a normal js object.
> I think if we get a serialization that maps directly onto a js object
> then we are done, e.g. we just need a representation that is
> consumable by javascript ... and I think e4x maybe the hook here.

E4X is only an extension to JavaScript, so it is only currently 
supported in Mozilla, and V8 (Chrome) is open to including it if a third 
party implements it: http://code.google.com/p/v8/issues/detail?id=235

E4X is treated as a fundamental type rather than as a regular object, 
with its own accessors which are JS object-like (and more powerful if 
filters are used, making it more XPath like).

For example,

var  friends=  <myData><friends>
<name  type="imaginary">Snuffaluffagus</name>
<name  type="real">Goober</name>
<name  type="imaginary">Tooth Fairy</name>

var  realFriends=  friends..name.(@type==  'real').toString();  // Goober

You can also reshape data. If we just change the equality check to an 

var  realFriends=  friends..name.(@type=  'real').toString();  // Goober

...we get as the results an "XMLList" (and the original element altered 
in place):

<name  type="real">Snuffaluffagus</name>
<name  type="real">Goober</name>
<name  type="real">Tooth Fairy</name>

To simulate some XQuery-like features, you might see 
https://developer.mozilla.org/en/E4X_for_templating , but E4X does not 
have a lot of built-in means of reshaping the XML other than as above or 
creating element names, attribute names, or attribute values and element 
content dynamically.

As far as serializing to more portable objects, there is a built-in 
method, "toXMLString()" for serializing the whole E4X object which 
represents the XML into a string (toString() will serialize the XML or 
return the text contents if the referenced element is only containing 
text). (Strings can in turn be converted to DOM objects or whatever.)

But there is no regular JSON traversal serialization.

Wonder if someone will make an E4X database that can also be XQueried... :)


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://x-query.com/pipermail/talk/attachments/20100726/78695ed0/attachment.htm


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.