Example usage for org.w3c.dom Node getNamespaceURI

List of usage examples for org.w3c.dom Node getNamespaceURI

Introduction

In this page you can find the example usage for org.w3c.dom Node getNamespaceURI.

Prototype

public String getNamespaceURI();

Source Link

Document

The namespace URI of this node, or null if it is unspecified (see ).

Usage

From source file:Main.java

public static List<String> getPropertiesFromXML(Node propNode) {
    ArrayList<String> properties;
    properties = new ArrayList<String>();
    NodeList childList = propNode.getChildNodes();

    for (int i = 0; i < childList.getLength(); i++) {
        Node currentNode = childList.item(i);
        if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
            String nodeName = currentNode.getLocalName();
            String namespace = currentNode.getNamespaceURI();
            // href is a live property which is handled differently
            properties.add(namespace + ":" + nodeName);
        }/*from w ww .j  av  a  2 s.  c om*/
    }
    return properties;
}

From source file:Main.java

public static Element getFirstChildElementNS(Element elm, String tns, String localName) {
    if (tns == null && localName == null)
        return getFirstChildElement(elm);

    if (tns == null || tns.length() == 0)
        return getFirstChildElement(elm, localName);

    NodeList nl = elm.getChildNodes();
    for (int c = 0; c < nl.getLength(); c++) {
        Node node = nl.item(c);
        if (node.getNodeType() != Node.ELEMENT_NODE)
            continue;

        if (localName == null && tns.equals(node.getNamespaceURI()))
            return (Element) node;

        if (localName != null && tns.equals(node.getNamespaceURI()) && localName.equals(node.getLocalName()))
            return (Element) node;
    }//  w  w w .j  ava2 s  .  c  om

    return null;
}

From source file:Main.java

public static Element getFirstChildElementNS(Element elm, String tns, String localName) {
    if (tns == null && localName == null)
        return getFirstChildElement(elm);

    if (tns == null)
        return getFirstChildElement(elm, localName);

    NodeList nl = elm.getChildNodes();
    for (int c = 0; c < nl.getLength(); c++) {
        Node node = nl.item(c);
        if (node.getNodeType() != Node.ELEMENT_NODE)
            continue;

        if (localName == null && tns.equals(node.getNamespaceURI()))
            return (Element) node;

        if (localName != null && tns.equals(node.getNamespaceURI()) && localName.equals(node.getLocalName()))
            return (Element) node;
    }/* ww  w  . j  a  v  a  2  s.c  o  m*/

    return null;
}

From source file:Main.java

static public boolean isA(Node e, String ns, String localname) {
    if (e == null)
        return false;
    //if(e.getNodeType()!=Node.ELEMENT_NODE) return false;
    return ns.equals(e.getNamespaceURI()) && e.getLocalName().equals(localname);
}

From source file:Main.java

/**
 * Returns the first child element that matches the given local name and
 * namespace. If no child element is present or no child element matches,
 * <code>null</code> is returned.
 *
 * @param parent/*from  w  w  w  . j av a  2 s. c  o m*/
 * @param childLocalName
 * @param childNamespaceURI
 * @return first child element matching the specified names or <code>null</code>.
 */
public static Element getChildElement(Node parent, String childLocalName, String childNamespaceURI) {
    if (parent != null) {
        NodeList children = parent.getChildNodes();
        for (int i = 0; i < children.getLength(); i++) {
            Node child = children.item(i);
            if (child.getNodeType() == Node.ELEMENT_NODE && childLocalName.equals(child.getLocalName())
                    && childNamespaceURI.equals(child.getNamespaceURI())) {
                return (Element) child;
            }
        }
    }
    return null;
}

From source file:de.betterform.xml.xforms.model.constraints.RelevanceSelector.java

private static void addElement(Document relevantDocument, Node instanceNode) {
    Element relevantElement;//from  w w w .  ja va  2  s  .  c  om

    if (instanceNode.getNamespaceURI() == null) {
        relevantElement = relevantDocument.createElement(instanceNode.getNodeName());
    } else {
        relevantElement = relevantDocument.createElementNS(instanceNode.getNamespaceURI(),
                instanceNode.getNodeName());
    }

    relevantDocument.appendChild(relevantElement);
    addAttributes(relevantElement, instanceNode);
    addChildren(relevantElement, instanceNode);
}

From source file:Main.java

/**
 * Node is element whose namespace is "namespace" and localname is "localname"?
 * /*from w  ww.  jav  a 2  s  . c  o m*/
 * @param node XML node.
 * @param namespace Namespace
 * @param localname Local name
 * @return Node is element whose namespace is "namespace" and localname is "localname"?
 */
public static boolean nodeIsElementOf(Node node, String namespace, String localname) {

    if (node.getNodeType() != Node.ELEMENT_NODE) {
        return false;
    }
    String ns = node.getNamespaceURI();

    if (((ns != null) && (namespace != null) && (ns.equals(namespace)))
            || ((ns == null) && (namespace == null))) {
    } else {
        return false;
    }

    String ln = node.getLocalName();
    if (!ln.equals(localname)) {
        return false;
    }
    return true;
}

From source file:Main.java

public static Map<String, Object> getPropertiesWithValuesFromXML(Node propNode) {
    Map<String, Object> propertiesWithValues = new HashMap<String, Object>();

    NodeList childList = propNode.getChildNodes();
    for (int i = 0; i < childList.getLength(); i++) {
        Node currentNode = childList.item(i);
        if (currentNode.getNodeType() == Node.ELEMENT_NODE) {
            String nodeName = currentNode.getLocalName();
            String namespace = currentNode.getNamespaceURI();
            // href is a live property which is handled differently
            String fqn = namespace + ":" + nodeName;
            propertiesWithValues.put(fqn, nodeValue(currentNode));

        }/*from  www  . ja v  a 2  s. c o m*/
    }
    return propertiesWithValues;
}

From source file:com.evolveum.midpoint.util.QNameUtil.java

public static QName getNodeQName(Node node) {
    return new QName(node.getNamespaceURI(), node.getLocalName());
}

From source file:Main.java

/**
 * Prints elements of the specified node.
 * //from w  w  w .  j a  v  a 2s  .com
 * @param node the specified node.
 * @param level a number of indent.
 */
private static void printElement(Node node, int level) {
    for (int i = 0; i < level; i++) {
        System.out.print("  ");
    }
    System.out.print("{" + node.getNamespaceURI() + "}");
    System.out.println(node.getNodeName());
    NamedNodeMap attrs = node.getAttributes();
    if (attrs != null) {
        for (int i = 0; i < attrs.getLength(); i++) {
            printNode(attrs.item(i), level + 1);
        }
    }

    NodeList children = node.getChildNodes();
    int n = children.getLength();
    for (int i = 0; i < n; i++) {
        Node child = children.item(i);
        printNode(child, level + 1);
    }
}