[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: [ANN] XQuery in the Browser, JavaScript Edition
As a follow-up, I've been playing with xqib-js on my laptop most of the evening, and my reaction to this has escalated from "cool" to "incredible!" to "this is a frigging game changer!!". I've already started writing an article on it, should have something published over the weekend. I've just been playing around with it, after installing the archive, and have ended up with a quick "test" script: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <title>XQIB: Sample page</title> <meta charset="UTF-8"/> <script type="text/javascript" src=""mxqueryjs/mxqueryjs.nocache.js"></script>
<script type="text/xml" src=""/lib/resources/colors.xml"" id="data"></script> <script type="text/xquery"> declare variable $foo := "XQuery!";
declare function local:get-color-list($url as xs:string) as node(){ (let $colors := fn:doc($url) return <div style="background-color:lightGray;">
<h3>Colors</h3> <ul>{ for $term in $colors//*:term return <li style="color:{$term/*:value}">
<span style="color:black">{fn:string($term/*:label)}</span> </li> } </ul></div>)
}; declare updating function local:main() { let $eltnames := ("h1","h2","h3","h4","h5","h6","fieldset")
let $elts := for $eltname in $eltnames return element {$eltname} {"This is a test. This is only a test."} let $bar := b:dom()//div[@id='bar'] let $table :=
<table> <tr> <th>Element Name</th> <th>Example Text</th> </tr>
{for $index in (1 to fn:count($elts)) return <tr> <td>{$eltnames[$index]}</td> <td>{$elts[$index]}</td>
</tr> } </table> return ( insert node <div>{$elts}</div> as first into $bar,
insert node $table as last into $bar, insert node <div>{fn:string-join(fn:tokenize("red,green,blue,yellow",","),";")}</div> as last into $bar,
insert node local:get-color-list("http://localhost:8100/lib/resources/colors.xml") as last into $bar, insert node <div>{$foo}</div> as last into $bar)
}; </script> </head> <body> <h1>Test Page</h1> <div id="bar"></div> <hr></hr>
</body> </html> The scripts are fast too - running this in both Chrome and Firefox, the refresh is a shade slower than what you'd expect for JavaScript by itself, but far faster than the plugin (which had a bad tendency to crash on me when I used it).
On game-changing - one of the central problems that XML has had on the web is that XML parsing using DOM is, to put it bluntly, a pain in the butt, yet it is how an overwhelming majority of the people working with web page content deal with it. Not surprisingly, this has led to the rise of JSON, which is certainly parseable in the Javascript world, but for people working with XML content on the server, JSON is a pain as well.
If the test that I see here is any indication, xqib-js may change that equation dramatically. I could easily see this as the foundation for an XQuery based XForms system. It makes both inline and externally loaded XML manipulation possible - indeed, makes it trivially simple. It puts XQuery into the hands of web developers, rather than just database developers, which should increase the number of XQuery skilled devs. It provides another client for XRX applications (I'm already envisioning how you could make a very effective database "reader" with it). It makes binding easy - instead of needing a specialized function for retrieving items of a given class, you can get a list of all items of a given class as
let $class-items := b:dom()//*[$class = tokenize(@class," ")] and then bind these to sets of events that generate differing representations depending upon the state of the relevant elements and the events in question.
Eagerly awaiting the completed suite, Kurt Cagle Managing Editor, http://xmltoday.org On Thu, Jan 6, 2011 at 7:08 PM, Kurt Cagle <kurt.cagle@gmail.com> wrote:
[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] |
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|