Java XML Child Element Add appendTextNode(Node parent, String child)

Here you can find the source of appendTextNode(Node parent, String child)

Description

append Text Node

License

Open Source License

Declaration

public static Node appendTextNode(Node parent, String child) 

Method Source Code

//package com.java2s;
/* ***** BEGIN LICENSE BLOCK *****
 *
 * This file is part of Weave.//from  w  ww .  ja  va 2  s.co m
 *
 * The Initial Developer of Weave is the Institute for Visualization
 * and Perception Research at the University of Massachusetts Lowell.
 * Portions created by the Initial Developer are Copyright (C) 2008-2015
 * the Initial Developer. All Rights Reserved.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/.
 * 
 * ***** END LICENSE BLOCK ***** */

import org.w3c.dom.Document;
import org.w3c.dom.Node;

import org.w3c.dom.Text;

public class Main {
    public static Node appendTextNode(Node parent, String child) {
        if (parent == null)
            System.err.println("parent null 0");
        if (parent instanceof Document)
            parent = ((Document) parent).getDocumentElement();
        if (parent == null)
            System.err.println("parent null 1");
        if (parent.getOwnerDocument() == null)
            System.err.println("parent ownerdoc null");
        if (child == null)
            System.err.println("child null");
        Text newNode = parent.getOwnerDocument().createTextNode(child);
        return parent.appendChild(newNode);
    }
}

Related

  1. addElement(Element parent, Element child)
  2. addElement(Element parent, Element childElement)
  3. addElementChildTo(Element parent, String nsURI, String qualifiedName)
  4. appendElement(Element parent, Element child)
  5. appendElement(Element parent, Element child)