Sunday, January 20, 2013

How to remove a child from Axiom object model


Just wanted to point out that there is a difference in API of removing a child between Axiom and DOM. The API of removing a child from a xml tree is different between Axiom and DOM. In DOM, we do following to remove a child.

childNode.getParentNode().removeChild(parentNode);

where childNode is an org.w3c.dom.Node instance.

Basically, what the above does is, when you want to remove a node from a document, it gets the parent node, and then calls the #removeChild to remove the given node from parent.

With Axiom, it's different. What we do is get the child node, and remove it's parent reference. For example,

            element = omFactory.createOMElement(name, null);
            OMElement element = (OMElement) xpathExpression2.selectSingleNode(documentElement);
            element.detach();

No comments:

Post a Comment