dojo xml parser
January 6th, 2008 byWe’ve been using dojo for a while now as part of our Ajax product offering. We’re currently in the process of upgrading from 0.4 to the shiny new dojo 1.0; as part of that we have developed some things that may be useful outside of the Nexaweb product. One of these is a processor, which uses the dojo parser, to read xml and uses it to create dojo components.
For example:
<ui xmlns:dijit=”dijit”>
<dijit:form.Button label=”Hello, World!”/>
</ui>
<ui xmlns:dijit=”dijit.form”>
<dijit:Button label=”Hello, World!”/>
</ui>
would both create a dojo button with the (grammatically correct) “Hello, World!”. The path to the component is the combination of the xml namespace and the element name. An event handler could be added simply by adding an onclick attribute.
HTML can be mixed in using its own namespace:
<ui xmlns:dijit=”dijit” xmlns:html=”html”>
<html:p>HTML before</html:p>
<dijit:form.Button label=”Hello, World!”/>
</ui>
These are all included in an HTML file through the <script/> tag, either inline or via the src attribute.
Why is this useful? It flips the ui description to a full declarative approach from either JavaScript or JavaScript + a div. This has some advantage: can be easier to write and maintain, the dojo part can be seperated from the rest of the HTML, easier to share, can be machine generated or schema validated for correctness, etc.
It’s not all peaches and cream - the declarations get longer and there is another, very short, step before the component is on the screen - but for many the benefits can outweigh the disadvantages.
You can try it yourself by downloading it here. Feedback and thoughts appreciated. More examples on their way.
- Rob Gagne
|
|