Dax Declarative Api For Xml

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    1 Group

    Dax Declarative Api For Xml - Presentation Transcript

    1. DAX: Where Flowscript meets XSLT Lars Trieloff, Mindquarry
    2. Lars Trieloff • Entrepreneur, Blogger, Open Source Coder • OSS Projects • Apache Cocoon • Mindquarry • Goshaky • DAX
    3. What is DAX • DAX means Declarative API for XML • A way to process XML • By expressing what parts of a document you want to process • Based on Java, Javascript and Cocoon
    4. DAX History • Feb 2005: Kim Wolk writes XMLTO, a .NET library that transforms XML into objects • March 2005: Ryan Cox ports it to Java 5, using Annotations and dom4j‘s Transformer API • 2006 to 2007: DAX is used in production at Mindquarry, adopted to Cocoon
    5. DAX Modules and Dependencies DAX
    6. DAX Modules and Dependencies DAX DAX-Java
    7. DAX Modules and Dependencies DAX DAX-Java dom4j
    8. DAX Modules and Dependencies DAX DAX- DAX-Java Javascript dom4j
    9. DAX Modules and Dependencies DAX DAX- DAX-Java Javascript dom4j Rhino
    10. DAX Modules and Dependencies DAX DAX- DAX- DAX-Java Javascript Cocoon dom4j Rhino
    11. DAX Modules and Dependencies DAX DAX- DAX- DAX-Java Javascript Cocoon dom4j Rhino Cocoon
    12. DAX-Java
    13. DAX-Java How to use it public class ElementCounter extends Transformer { Map elements = new Hashmap<String, Integer>(); public void processElement(Node context) { String name = context.getName(); if (elements.hasKey(name)) { elements.put(name, elements.get(name) + 1); } else { elements.put(name, 1); } } }
    14. DAX-Java How to use it public class ElementCounter extends Transformer { Map elements = new Hashmap<String, Integer>(); @Path(\"*\") //select all elements public void processElement(Node context) { String name = context.getName(); if (elements.hasKey(name)) { elements.put(name, elements.get(name) + 1); } else { elements.put(name, 1); } } }
    15. DAX-Java How to use it public class SourceCounter extends Transformer { Map sources = new Hashmap<String, Integer>(); @Path(\"img[@src]\") //select all elements public void processElement(Node context) { String name = this.valueOf(\"@src\"); if (elements.hasKey(name)) { elements.put(name, elements.get(name) + 1); } else { elements.put(name, 1); } } }
    16. DAX-Java How it works • Simple parsing algorithm: • traverse the DOM of the XML document • for each node, find an annotated method • with matching XPath • execute this method • Just like XSLT's templates
    17. DAX-Java vs XSLT DAX-Java XSLT @Path(\"/foo/bar\") Templates public void bar(Node context) <xsl:template match=\"/foo/bar\"> Value-Of valueOf(\"@bar\") <xsl:value-of select=\"@bar\" /> Apply- applyTemplates() <xsl:apply-templates /> Templates
    18. DAX-Javascript
    19. DAX-Javascript Why? • XSLT is fine for transforming XML • but no side-effects possible • no access to external data model Input XSLT Output ? Model
    20. DAX-Javascript Background • Map most important XSLT concepts to Javascript concepts XSLT Javascript <xsl:stylesheet> Stylesheet object template function of the Stylesheet <xsl:template> object applyTemplate function of the <xsl:apply-templates/> Stylesheet object copy function of the Stylesheet object <xsl:copy/> (with inlined body function)
    21. DAX-Javascript How to use it <xsl:template match=\"foo\"> <bar> <xsl:comment>example code uses foo</xsl:comment> <xsl:apply-templates /> </bar> </xsl:template/> Stylesheet.template({match:\"foo\"}, function(node) { this.element(\"bar\", function(node) { this.comment(\"example code uses foo\"); this.applyTemplates(); }); });
    22. DAX-Javascript How to use it <xsl:template match=\"node()|@*\"> <xsl:copy> <xsl:apply-templates select=\"node()|@*\" /> </xsl:copy> </xsl:template/> Stylesheet.template({match:\"node()|@*\"}, function (node) { this.copy(function(node) { this.applyTemplates({select:\"node()|@*\"}) }); });
    23. DAX-Javascript How it works • Uses Rhino Javascript Engine • full access to Java object model • allows side-effects when transforming XML • Parses the incoming XML stream • Finds and fires matching functions
    24. DAX-Cocoon
    25. DAX-Cocoon How to use it <map:components> <map:transformers> <map:transformer name=\"dax\" src=\"dax.cocoon.DAXTransformer\" /> </map:transformers> </map:components>
    26. DAX-Cocoon How to use it <map:match pattern=\"/resource/*\"> <map:select type=\"request-method\"> <map:generate type=\"stream\" /> <map:when test=\"PUT\"> <map:transform type=\"dax\" src=\"dax/res.js\"> <map:parameter name=\"res\" value=\"{1}\" /> </map:transform> </map:when> </map:select> </map:match>
    27. DAX-Cocoon How to use it var resourcemanager = cocoon.getComponent(\"resourcemanager\"); Stylesheet.template({match:\"del\"}, function(node) { var that = this; this.copy(function(node) { if (that.valueOf(\".\")==cocoon.parameters.res) { resourcemanager.delete(that.valueOf(\"@node\")) } this.applyTemplates({select:\"node()|@*\"}) }); });
    28. DAX-Cocoon How it works • Implemented as a Cocoon Transformer • Pull in \"cocoon\" object as Flowscript does • Usage Scenario: REST Application • validate using DAX (e.g. by checking database) • transform using DAX (e.g by triggering actions) • save using DAX (e.g. by changing model)
    29. DAX-Cocoon Open Questions • Caching • We do not know if a transformation has non-cacheable side-effects • Mixing DAX and XSLT • perhaps E4X is a way to conveniently embed XSLT • Not all XSLT concepts implemented (sorting)
    30. How to go on? • Read more • http://www.asciiarmor.com/2005/03/03/introducing- dax-declarative-api-for-xml/ • https://www.mindquarry.org/wiki/dax/ • http://www.codeconsult.ch/bertrand/archives/ 000802.html • Download • http://releases.mindquarry.org/dax/ • (Maven artifacts available)
    31. Thank you very much lars@trieloff.net For more information, see my weblog at http://weblogs.goshaky.com/weblog/lars

    + Lars TrieloffLars Trieloff, 3 years ago

    custom

    2553 views, 0 favs, 2 embeds more stats

    DAX is a declarative API for processing XML in Java more

    More info about this document

    CC Attribution License

    Go to text version

    • Total Views 2553
      • 2528 on SlideShare
      • 25 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 62
    Most viewed embeds
    • 24 views on http://weblogs.goshaky.com
    • 1 views on http://feeds.feedburner.com

    more

    All embeds
    • 24 views on http://weblogs.goshaky.com
    • 1 views on http://feeds.feedburner.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Groups / Events