You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Lingzhi Zhang <lz...@cse.ogi.edu> on 2003/11/11 20:02:13 UTC
insert node into DOM
Hi,
I am using xerces to try to insert xml into the certain node in the DOM
which satisfies some xpath expression. The simple structure of my original
xml is like
<root>
<A><B>10</B></A>
<A><B>10</B></A>
</root>
I try to run "insert <A>new</A> //A[B=10]", and my code is like
NodeIterator i = XPathAPI.selectNodeIterator(contextNode, xPath);
Node node;
while((node = i.nextNode()) != null) {
Node parent = node.getParentNode();
parent.insertBefore(docFrag, node);
}
There should be two insertions before each of the <A><B>10</B></A>,
however, I just got one. It just inserts the <A>new</A> before the first
<A><B>10</B></A>, while not the second. I check my code, it dose call
parent.insertBefore(docFrag, node) twice, which makes me very
confused. Any idea what's wrong? Thanks.
Stephen
PS:
expected result:
<root>
<A>new</A>
<A><B>10</B></A>
<A>new</A>
<A><B>10</B></A>
</root>
actual result:
<root>
<A>new</A>
<A><B>10</B></A>
<A><B>10</B></A>
</root>
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org