Exercises to be handed-in marked with a star. Hand-in friday morning.
Document ownerDocument // the XML document root node of current node
Node parentNode // parent node of current node
Node insertBefore(Node newChild, Node refChild)
// inserts newChild before refChild of current node,
// returns inserted node
// ... more child manipulation methods like insertBefore
Node cloneNode(boolean deep) // clones a node shallow or deep
A node can be thought of as containing: a pointer to its root node, a pointer to its immediate parent, and a pointer to its children. The children can be thought of implemented using a doubly-linked list connecting the children.
The newChild argument node in the
insertBefore method is unlinked from its parent before
being inserted into the list of children of the current node. Why?
If we want to a DOM node n to occur twice in the list of
children of another node p, how can this be programmed in DOM?
In the latter case, how do you program an update of the node
n; e.g., changing its chardata from "blib" to "blob"?
Node changeCharData(String old, String new, Node node)where
node is the node to traverse recursively
looking for old-strings, and the return value is the
new node. Hint: Think of
the example from class where we changed one speaker from Hamlet
to Ophelia.