Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] best way to bind java classes to xom classes?

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Steve Loughran <steve.loughran AT gmail.com>
  • To: xom-interest <xom-interest AT lists.ibiblio.org>
  • Subject: [XOM-interest] best way to bind java classes to xom classes?
  • Date: Fri, 17 Jun 2005 09:23:57 +0100

Hello,

I have a java program that works with XML, using Xom. To make that
work easier, I have various java classes that work with the Xom nodes,
e.g.

class PropertyList {
Element element;
....

}

At the same time, I am working with the classes at the XML level,
manipulating elements, which makes it very hard of me to map from xom
Nodes to my wrapper classes. I end up having to effectively rebuild
first the doc tree, then rebuild my wrapper classes by walking the Xom
tree again.

private PropertyList replaceNode(PropertyList target, List<Node>
newChildren)
throws CdlXmlParsingException {
//copy the target element
Element newElement = (Element) target.getNode().copy();
//strip its children away
newElement.removeChildren();
//add the new ones in order
for (Node sprog : newChildren) {
sprog.detach();
newElement.appendChild(sprog);
}
//here we have our new element, ready to go
PropertyList resultTemplate = new PropertyList(newElement);
return resultTemplate;
}

It seems to me, that a more effective solution would be trivial were
every Xom node to have an Object data; element at the end that would
let me store a back pointer. The alternative would be to hide a back
pointer inside a attribute (@impl:owner="0xfeedf00d" , but that not
only alters the document, it is hard to do in Java, given that
pointers are hidden.

Is there some obvious solution I am missing?

-steve




Archive powered by MHonArc 2.6.24.

Top of Page