List of usage examples for org.w3c.dom Document createComment
public Comment createComment(String data);
Comment
node given the specified string. From source file:Main.java
public static void replaceNode(Document doc, Node parent, Node oldNode, Node newNode) { Node comment = doc.createComment(" Updated by FM GUI @ " + (new Date()) + " "); parent.insertBefore(comment, oldNode); parent.replaceChild(newNode, oldNode); formatNode(doc, parent, newNode);//from w w w. j a v a2 s . com }
From source file:Main.java
public static 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);/*w ww . j a v a 2 s .c o m*/ }
From source file:Main.java
/** * Adds a commentary to an element of a document in memory <br> * (It's supposed that the element is one of the document) * //from ww w . java 2 s . c o m * @param doc * Document of the element where the commentary will be added * @param element * The xml elemnet where the commentary will be added * @param commentary * The commentary text * * @return org.w3c.dom.Comment */ public static Comment addCommentary(Document doc, Element element, String commentary) { // Creates the commentary and adds it to the element Comment comment = doc.createComment(commentary); element.appendChild(comment); return comment; }
From source file:Main.java
/** * //from www . jav a2 s .c om * <i>Description:</i> append a node into specified <code>parent</code> node * * @param doc * @param parent * @param node */ public static void appendNode(Document doc, Node parent, Node node) { Node txt = doc.createTextNode("\n "); parent.appendChild(txt); Node comment = doc.createComment(" Created by FM GUI @ " + (new Date()) + " "); parent.appendChild(comment); doc.adoptNode(node); parent.appendChild(node); formatNode(doc, parent, node); txt = doc.createTextNode("\n\n "); parent.appendChild(txt); }
From source file:Main.java
public static Comment addComment(Node node, String comment) { Document doc = null; if (node.getNodeType() == Node.DOCUMENT_NODE) { doc = (Document) node;/*from w ww . j ava2s . c o m*/ } else { doc = node.getOwnerDocument(); } Comment e = doc.createComment(comment); node.appendChild(e); return e; }
From source file:Main.java
public static void createChildTextWithComment(Document doc, Element elem, String name, String value, String comment) {/*w ww . j ava 2s . c o m*/ Element child = doc.createElement(name); child.appendChild(doc.createTextNode(value == null ? "" : value)); Comment c = doc.createComment(comment); elem.appendChild(c); elem.appendChild(child); }
From source file:Main.java
/** * // w ww .j a v a 2s . co m * @param doc * @param elem * @param name * @param value * @param comment */ public static void createChildTextWithComment(Document doc, Element elem, String name, String value, String comment) { Element child = doc.createElement(name); child.appendChild(doc.createTextNode(value == null ? "" : value)); Comment c = doc.createComment(comment); elem.appendChild(c); elem.appendChild(child); }
From source file:DOMEdit.java
public static 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); }/* w w w.j a va2 s . c o m*/
From source file:Main.java
public static void createChildTextWithComment(Document paramDocument, Element paramElement, String paramString1, String paramString2, String paramString3) { Element localElement = paramDocument.createElement(paramString1); localElement.appendChild(paramDocument.createTextNode((paramString2 == null) ? "" : paramString2)); Comment localComment = paramDocument.createComment(paramString3); paramElement.appendChild(localComment); paramElement.appendChild(localElement); }
From source file:Main.java
@SuppressWarnings("null") public static void copyInto(Node src, Node dest) throws DOMException { Document factory = dest.getOwnerDocument(); //Node start = src; Node parent = null;//from w w w.j a v a 2 s. com Node place = src; // traverse source tree while (place != null) { // copy this node Node node = null; int type = place.getNodeType(); switch (type) { case Node.CDATA_SECTION_NODE: { node = factory.createCDATASection(place.getNodeValue()); break; } case Node.COMMENT_NODE: { node = factory.createComment(place.getNodeValue()); break; } case Node.ELEMENT_NODE: { Element element = factory.createElement(place.getNodeName()); node = element; NamedNodeMap attrs = place.getAttributes(); int attrCount = attrs.getLength(); for (int i = 0; i < attrCount; i++) { Attr attr = (Attr) attrs.item(i); String attrName = attr.getNodeName(); String attrValue = attr.getNodeValue(); element.setAttribute(attrName, attrValue); /* if (domimpl && !attr.getSpecified()) { ((Attr) element.getAttributeNode(attrName)).setSpecified(false); } */ } break; } case Node.ENTITY_REFERENCE_NODE: { node = factory.createEntityReference(place.getNodeName()); break; } case Node.PROCESSING_INSTRUCTION_NODE: { node = factory.createProcessingInstruction(place.getNodeName(), place.getNodeValue()); break; } case Node.TEXT_NODE: { node = factory.createTextNode(place.getNodeValue()); break; } default: { throw new IllegalArgumentException( "can't copy node type, " + type + " (" + node.getNodeName() + ')'); } } dest.appendChild(node); // iterate over children if (place.hasChildNodes()) { parent = place; place = place.getFirstChild(); dest = node; } else if (parent == null) { place = null; } else { // advance place = place.getNextSibling(); while (place == null && parent != null && dest != null) { place = parent.getNextSibling(); parent = parent.getParentNode(); dest = dest.getParentNode(); } } } }