Java XML Text Node Create extractOrCreateTextNode(Element filenameElement, String defaultText)

Here you can find the source of extractOrCreateTextNode(Element filenameElement, String defaultText)

Description

extract Or Create Text Node

License

Open Source License

Declaration

public static Text extractOrCreateTextNode(Element filenameElement, String defaultText) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import org.w3c.dom.Text;

public class Main {
    public static Text extractOrCreateTextNode(Element filenameElement, String defaultText) {
        Document rootDoc = filenameElement.getOwnerDocument();
        if (filenameElement.getChildNodes().item(0) instanceof Text) {
            return (Text) filenameElement.getChildNodes().item(0);
        }/*  ww  w .j a va 2  s .co m*/
        Text textNode = rootDoc.createTextNode(defaultText);
        filenameElement.appendChild(textNode);
        return textNode;
    }
}

Related

  1. createTextNode(Document doc, String elemName, String attrName, String attrValue, String content)
  2. createTextNode(Document doc, String string)
  3. createTextNode(Element element, String nodeName, String textValue)
  4. createTextNode(Node doc, String elementName, String elementText)
  5. createTextNode(Node node, String data)
  6. getFirstNodeFromPath(Node contextNode, final String[] path, final boolean create)