List of usage examples for org.w3c.dom Document createTextNode
public Text createTextNode(String data);
Text
node given the specified string. From source file:Main.java
/** * Creates a text node with the given content and appends it as child to the given element. * // w ww. jav a 2 s . c om * @param domElement the element to recieve the text node * @param textContent the content for the text node */ public static void appendTextContent(Element domElement, String textContent) { if (textContent == null) { return; } Document parentDocument = domElement.getOwnerDocument(); Text textNode = parentDocument.createTextNode(textContent); domElement.appendChild(textNode); }
From source file:Main.java
private static void formatNode(Document doc, Node parent, Node node) { Node txt = doc.createTextNode("\n "); parent.insertBefore(txt, node);/*from www . j a v a 2 s . c o m*/ NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { txt = doc.createTextNode("\n "); node.insertBefore(txt, children.item(i)); i += 1; } txt = doc.createTextNode("\n "); node.appendChild(txt); }
From source file:Main.java
public static Node createTextNode(Document document, String elTag, String value) { Node elem = document.createElement(elTag); Node text = document.createTextNode(value); elem.appendChild(text);/* w w w . j av a 2s. c om*/ return elem; }
From source file:Main.java
public static Element createElementWithText(Document doc, String tagName, String text) { Element elem = doc.createElement(tagName); elem.appendChild(doc.createTextNode(text)); return elem;//from w w w . j av a 2 s .c o m }
From source file:Main.java
public static void addTextTag(Node node, String tagName, String text) { Document doc = node.getOwnerDocument(); Element elem = doc.createElement(tagName); elem.appendChild(doc.createTextNode(text)); node.appendChild(elem);//from w w w.j ava 2 s. c o m }
From source file:Main.java
/** * Creates ElementNode for given tag with particular text as content. *///from www. jav a2 s .com public static Element createTextNode(String tag, String content) throws ParserConfigurationException { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); Document doc = docBuilder.newDocument(); Element node = doc.createElement(tag); Text t = doc.createTextNode(content); node.appendChild(t); return node; }
From source file:Main.java
/** * Creates an element representing {@code <tag>text</tag>}. * * @param doc//from w w w . ja va 2 s .co m * The {@link Document} containing the {@link Element}. * @param tag * The tag name of the created {@link Element}. * @param text * The content of the created {@link Element}. * @return the {@link Element} created. */ public static Element createField(Document doc, String tag, String text) { Element elem = doc.createElement(tag); elem.appendChild(doc.createTextNode(text)); return elem; }
From source file:Main.java
/** Add a Text element to a Document */ public static Text addChildTextElement(Document doc, Node parent, String tag, String value) { Element e = doc.createElement(tag); Text t = doc.createTextNode(value); e.appendChild(t);/*from w w w . j a v a2s.c o m*/ parent.appendChild(e); return t; }
From source file:Main.java
/** * /*from w w w.ja v a 2 s. c o m*/ * <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
private static Element createElementWithContent(Document doc, String tagName, String content) { Element node = doc.createElement(tagName); node.appendChild(doc.createTextNode(content)); return node;//from ww w.j a v a2s . com }