Here you can find the source of addTextNode(Document XMLDocument, Node rootElement, String tagName, String text)
Parameter | Description |
---|---|
XMLDocument | current XML document |
rootElement | element you want append the new node to |
tagName | node's tag name |
text | text in the node |
public static void addTextNode(Document XMLDocument, Node rootElement, String tagName, String text)
//package com.java2s; /**//w ww . j av a2s .c om (C) Copyright 1998-2007 Hewlett-Packard Development Company, LP This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA For more information: www.smartfrog.org */ import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.Element; public class Main { /** * Adds a simple DOM Node like <tagName>text</tagName> to a given node in a document * * @param XMLDocument current XML document * @param rootElement element you want append the new node to * @param tagName node's tag name * @param text text in the node */ public static void addTextNode(Document XMLDocument, Node rootElement, String tagName, String text) { Element newNode = XMLDocument.createElement(tagName); newNode.appendChild(XMLDocument.createTextNode(text)); rootElement.appendChild(newNode); } }