Android XML Document Create getOrCreateElement(Document doc, Element manifestElement, String elementName)

Here you can find the source of getOrCreateElement(Document doc, Element manifestElement, String elementName)

Description

get Or Create Element

Declaration

public static Element getOrCreateElement(Document doc,
            Element manifestElement, String elementName) 

Method Source Code

//package com.java2s;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import org.w3c.dom.NodeList;

public class Main {
    public static Element getOrCreateElement(Document doc,
            Element manifestElement, String elementName) {
        NodeList nodeList = manifestElement
                .getElementsByTagName(elementName);
        Element element = null;/* w  w w.j a  v a 2s . com*/
        if (nodeList.getLength() == 0) {
            element = doc.createElement(elementName);
            manifestElement.appendChild(element);
        } else {
            element = (Element) nodeList.item(0);
        }
        return element;
    }
}

Related

  1. newDocument(String rootName)
  2. stringToDocument(String xmlString)
  3. stringToDocument(String xmlString)
  4. createDocument(final String source, boolean isNamespaceAware)
  5. createXml(Document document)
  6. getDomElement(File xmlFile)
  7. getDomElement(String aXml)
  8. LoadXml(String xml)