Answer the question
In order to leave comments, you need to log in
Why doesn't inserting a comment node after every node with a specific name in an XML document work?
I wrote this code, and it does not work as it should:
NodeList ourTags = root.getElementsByTagName(tagName);
Node commentTag = document.createComment(comment);
for (int i = 0; i < ourTags.getLength(); i++) {
if (ourTags.item(i).getNodeType() == Node.ELEMENT_NODE) {
Element element = (Element) ourTags.item(i);
Node n = element.getParentNode().insertBefore(commentTag, element);
System.out.println(n);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question