I write the same detailed DOM manipulation code again and again:
Element e1 = document.createElement("some-name"); e1.setAttribute("attr1", "val1"); e2.setAttribute("attr2", "val2"); document.appendChild(e1); Element e2 = document.createElement("some-other-name"); e.appendChild(e2); // Etc, the same for attributes and finding the nodes again: Element e3 = (Element) document.getElementsByTagName("some-other-name").item(0);
Now I do not want to change the architecture together, i.e. I do not want to use JDOM, JAXB or anything else. Just Java org.w3c.dom . The reasons for this are
- It's about the old and big old system
- XML is used in many places, and XSLT is converted several times to get XML, HTML, PDF file.
- I'm just looking for convenience, not big changes.
I'm just wondering if there is a good wrapper library (e.g. with apache commons or google) that allows me to do similar things using a free style like jRTF :
// create a wrapper around my DOM document and manipulate it: // like in jRTF, this code would make use of static imports dom(document).add( element("some-name") .attr("attr1", "val1") .attr("attr2", "val2") .add(element("some-other-name")), element("more-elements") );
and then
Element e3 = dom(document).findOne("some-other-name");
The important requirement that I have here is that I explicitly want to work with org.w3c.dom.Document , which
- already exists
- quite big
- a little manipulation is required.
Thus converting org.w3c.dom.Document to JDOM, dom4j, etc. seems like a bad idea. I would prefer to wrap it with adapters.
If it does not exist, I can overturn it, as this jRTF syntax looks very nice! And for XML, this seems pretty easy to implement, since there are only a few node types. It can be as powerful as jQuery from a smooth API perspective!