Listing 4. Adding a node
public static Node appendNode(Node startNode, String name, String xql)
throws Exception
{
Node targetNode = XPathAPI.selectSingleNode( startNode,xql );
Document doc = startNode.getOwnerDocument();
Element newElement = doc.createElement( name );
targetNode.appendChild( (Node) newElement );
return ( (Node) newElement );
}
|