H
Ha
I am trying to move a node of a tree up one level.
Example: I want to move C to be a child of A, then remove B.
Before:
<A>
<B>
<C>
<D/>
<E/>
</C>
</B>
</A>
After:
<A>
<C>
<D/>
<E/>
</C>
</A>
Here's the code I'm using. For some reason the children do not get added.
What am I missing?
NodeList nodeListB = document.getElementsByTagName("B");
Node BNode = nodeListMsgsRs.item(0);
Node ANode = eventsMsgsRsNode.getParentNode();
//these are the children of <B>
NodeList childrenBNodes = BNode.getChildNodes();
//add all of the children of <>B to B's parent <A>
for(int i =0; i<childrenBNodes.getLength(); i++){
Node childNode = childrenBNodes.item(i);
ANode.appendChild(childNode);
}
//now remove the emptied <B>
ANode.removeChild(BNode);
Example: I want to move C to be a child of A, then remove B.
Before:
<A>
<B>
<C>
<D/>
<E/>
</C>
</B>
</A>
After:
<A>
<C>
<D/>
<E/>
</C>
</A>
Here's the code I'm using. For some reason the children do not get added.
What am I missing?
NodeList nodeListB = document.getElementsByTagName("B");
Node BNode = nodeListMsgsRs.item(0);
Node ANode = eventsMsgsRsNode.getParentNode();
//these are the children of <B>
NodeList childrenBNodes = BNode.getChildNodes();
//add all of the children of <>B to B's parent <A>
for(int i =0; i<childrenBNodes.getLength(); i++){
Node childNode = childrenBNodes.item(i);
ANode.appendChild(childNode);
}
//now remove the emptied <B>
ANode.removeChild(BNode);