-
Fluent Interface for building XML Documents (9 messages)
- Posted by: Mathieu Carbou
- Posted on: September 13 2008 16:48 EDT
XML Tool is a Java library to help developers using XML document. You can build new documents, load existing documents, and execute all sorts of operations onto: delete, renaming, adding tags, attributes, text, data, namespaces, ... Navigation by XPath is also supported. Since it uses the Fluent Interface pattern, you don't have to know about plenty of classes, but just one: XMLDoc. From there, you can just use your IDE's code completion to check for available methods and call them consecutively. You can download / checkout XML Tool from http://code.google.com/p/xmltool/Threaded Messages (9)
- Re: Fluent Interface for building XML Documents by Kit Davies on September 15 2008 08:21 EDT
- Re: Fluent Interface for building XML Documents by Richard Wallace on September 15 2008 12:36 EDT
- Re: Fluent Interface for building XML Documents by Kit Davies on September 17 2008 04:22 EDT
- Re: Fluent Interface for building XML Documents by Richard Wallace on September 15 2008 12:36 EDT
- Re: Fluent Interface for building XML Documents by John Spencer on September 15 2008 15:54 EDT
- Re: Fluent Interface for building XML Documents by Mathieu Carbou on September 15 2008 20:30 EDT
- The "Fluent" Pattern.... by Karl Banke on September 16 2008 04:35 EDT
- https://txw.dev.java.net/ by Kohsuke Kawaguchi on September 16 2008 08:51 EDT
- JDK compatiblity by mansoor ashraf on September 16 2008 10:17 EDT
- Why build an intermediate useless (DOM[-like]) tree? by Tatu Saloranta on September 17 2008 01:32 EDT
-
Re: Fluent Interface for building XML Documents[ Go to top ]
- Posted by: Kit Davies
- Posted on: September 15 2008 08:21 EDT
- in response to Mathieu Carbou
Interesting, though maybe too close to regular DOM for my liking. When it comes to building documents, I wrote a Groovy script that takes an XSD and produces a fluent API for constructing documents conforming to it. Element/attribute names map to method calls on the builder. XML construction with intellisense! Good luck Kit -
Re: Fluent Interface for building XML Documents[ Go to top ]
- Posted by: Richard Wallace
- Posted on: September 15 2008 12:36 EDT
- in response to Kit Davies
I was thinking of doing the same thing after writing a small, type-safe, XHTML builder in Java. Any code you can make available? -
Re: Fluent Interface for building XML Documents[ Go to top ]
- Posted by: Kit Davies
- Posted on: September 17 2008 04:22 EDT
- in response to Richard Wallace
I'll need to dig it out. Pls email me at kdavies -at- kidare -dot- com . Regards Kit -
Re: Fluent Interface for building XML Documents[ Go to top ]
- Posted by: John Spencer
- Posted on: September 15 2008 15:54 EDT
- in response to Mathieu Carbou
Have you seen the XML thing Anders Noras (the guy who started Quare) posted on his blog? http://andersnoras.com/blogs/anoras/archive/2007/04/25/xml-dsl-for-java-1-5.aspx Looks more like XML than anything else. -
Re: Fluent Interface for building XML Documents[ Go to top ]
- Posted by: Mathieu Carbou
- Posted on: September 15 2008 20:30 EDT
- in response to John Spencer
Hi, Yes i read his blog. He took another track: a DSL one. Like Hamcrest, you have to import all static methods of a class and chain method calls, and also know what method is available to use it. This is quite different from a the fluent interface way: it is much more like Google Guice Binder for example, where you do not have to know about which method exist. Both are useful. To my mind, a the big difference is that a DSL provides better reading for a specific need, and FI provides better intuitive use of something. -
The "Fluent" Pattern....[ Go to top ]
- Posted by: Karl Banke
- Posted on: September 16 2008 04:35 EDT
- in response to Mathieu Carbou
...is somewhat overused. Take the example code (copied below and assuming it is correct) where the call to .gotoRoot().addTag("other:foo") apparently places you at the level of the Tag - otherwise the goto Root method() would be meaningless - but it returns an XMLDocument!. The outcome thus, is an XML Document with a state pointer asscociated with it. XMLDocument doc = XMLDoc.newDocument() .addDefaultNamespace("http://www.w3.org/2002/06/xhtml2/") .addNamespace("wicket", "http://wicket.sourceforge.net/wicket-1.0") .addRoot("html") .addTag("wicket:border") .gotoRoot().addTag("head") .addNamespace("other", "http://other-ns.com") .gotoRoot().addTag("other:foo"); -
https://txw.dev.java.net/[ Go to top ]
- Posted by: Kohsuke Kawaguchi
- Posted on: September 16 2008 08:51 EDT
- in response to Mathieu Carbou
Sorry for a shameless plug, but I have a similar project called TXW (https://txw.dev.java.net/). It can be used to generate any well-formed document, but it also comes with a compiler so that you can compile a schema into interfaces for better typesafety. -
JDK compatiblity[ Go to top ]
- Posted by: mansoor ashraf
- Posted on: September 16 2008 10:17 EDT
- in response to Kohsuke Kawaguchi
This looks like something i can use on a project. Is its 1.5 compatible? -
Why build an intermediate useless (DOM[-like]) tree?[ Go to top ]
- Posted by: Tatu Saloranta
- Posted on: September 17 2008 01:32 EDT
- in response to Mathieu Carbou
Looks like most xml content output variants basically just want to replicate inefficient bulky DOM with some convenience sugar. This does not make sense to me -- if you essentially call output methods in sequence, why not take use of it and keep things light-weight and fast? Actual output using SAX or Stax has similar speedup ratio to parsing; that is, it is 3-5x faster; and memory usage is bounded as opposed to relative to output size. So here's an alternate idea, in form of a shameless plug: lean output (and input...) is exactly what StaxMate (http://staxmate.codehaus.org) does. You do build content using output objects, similar to node objects. But the output goes straight to the underlying streaming xml writer (unless you explicitly want to buffer things via buffered output objects, for out-of-order output). This has been tested to perform at level very much like "raw" Stax xml writing, but with more compact and convenient code.