Java DOM edit: Insert a Processing Instruction and a Comment
public void addComment(Document doc) {
Element root = doc.getDocumentElement();
Element folks = (Element)root.getLastChild();
Comment comment = doc.createComment("Text of the comment");
root.insertBefore(comment,folks);
}
public void addProcessingInstruction(Document doc) {
Element root = doc.getDocumentElement();
Element folks = (Element)root.getLastChild();
ProcessingInstruction pi;
pi = (ProcessingInstruction)doc.createProcessingInstruction(
"validate",
"phone=\"lookup\"");
root.insertBefore(pi,folks);
}
Related examples in the same category