bug: insertBefore() with DocumentFragments
Nic Ferrier <[email protected]>
| Newsgroups | gmane.comp.java.classpath.extensions.xml |
|---|---|
| Message-ID | <[email protected]> |
inserting DocumentFragments with multiple children in them doesn't
seem to work.
with one child it works, with multiples it doesn't.
The following code illustrates the problem:
String[] toAdd = ...
String clauseToAdd = ...
Element toEdit = ... // some element in the Document.
// Get a doc fragment containing one child for each of
// the clauses specified in toAdd[] (these come from other docs).
DocumentFragment clauseToAdd = precedentDOM.createDocumentFragment();
getClauses(toAdd, clauseToAdd);
// Add the contents of the fragment AFTER the toEdit element.
Node clauseSection = (Element) toEdit.getParentNode();
if (clauseSection.getChildNodes().getLength() == 1)
clauseSection.appendChild(clauseToAdd);
else {
Node insertionPoint = toEdit.getNextSibling();
while (! (insertionPoint instanceof Element))
insertionPoint = insertionPoint.getNextSibling();
/////// this line causes the problem.
clauseSection.insertBefore(clauseToAdd, insertionPoint);
}
I get a NullPointerException,
at gnu.xml.dom.DomNode.insertBefore(DomNode.java:585)
at gnu.xml.dom.DomNode.insertBefore(DomNode.java:614)
The method works perfectly well with the crimson in the jdk.
Nic