Android XML Document Append createNode(Document d, String nameSpace, String name)

Here you can find the source of createNode(Document d, String nameSpace, String name)

Description

create Node

License

Open Source License

Declaration

public static Element createNode(Document d, String nameSpace,
            String name) 

Method Source Code

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

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

public class Main {
    public static Element createNode(Document d, String nameSpace,
            String name) {//from ww w . j  a  v  a2 s .  c  o m
        if (nameSpace == null || nameSpace.length() == 0)
            return d.createElement(name);
        Element e = d.createElementNS(nameSpace, name);

        // get prefix...
        NamedNodeMap map = d.getDocumentElement().getAttributes();
        int i = 0;
        int n = map.getLength();
        for (i = 0; i < n; i++) {
            Attr attr = (Attr) map.item(i);
            String nsUri = attr.getNamespaceURI();
            if (nsUri == null)
                continue;
            if (nsUri.equals("http://www.w3.org/2000/xmlns/")
                    && attr.getValue().equals(nameSpace)) {
                // found prefix...
                e.setPrefix(attr.getLocalName());
            }
        }

        return e;
    }
}

Related

  1. appendTextNode(String tagName, String textContent, Document doc)
  2. buildPlayerNode(Document doc, String user, String addy, double lat, double lng)
  3. createAttribute(Document document, String name, String value)
  4. createElementWithCDATASection(Document document, String name, String value)
  5. createElementWithTextNode(Document document, String name, String value)
  6. createXmlElement(Document xml, Element parent, String name)