Example usage for org.w3c.dom NamedNodeMap getNamedItemNS

List of usage examples for org.w3c.dom NamedNodeMap getNamedItemNS

Introduction

In this page you can find the example usage for org.w3c.dom NamedNodeMap getNamedItemNS.

Prototype

public Node getNamedItemNS(String namespaceURI, String localName) throws DOMException;

Source Link

Document

Retrieves a node specified by local name and namespace URI.

Usage

From source file:org.kalypsodeegree.xml.XMLTools.java

/**
 * Returns the attribute value of the given node.
 */// w ww .j av a  2  s .com
public static String getAttrValue(final Node node, final String namespace, final String attrName) {
    // get attr name and dtype
    final NamedNodeMap atts = node.getAttributes();

    if (atts == null) {
        return null;
    }

    final Attr a = (Attr) atts.getNamedItemNS(namespace, attrName);

    if (a != null) {
        return a.getValue();
    }

    return null;
}

From source file:org.ojbc.util.xml.TestXmlUtils.java

@Test
public void testAddAttribute() throws Exception {
    Document d = db.newDocument();
    Element e1 = d.createElementNS(OjbcNamespaceContext.NS_PERSON_SEARCH_RESULTS_EXT, "e1");
    d.appendChild(e1);/*from   w  w  w  . j ava 2 s.c  o m*/
    XmlUtils.addAttribute(e1, "foo", "a", "baz");
    NamedNodeMap aa = e1.getAttributes();
    assertEquals(1, aa.getLength());
    Node n = aa.getNamedItemNS("foo", "a");
    assertNotNull(n);
    assertEquals("baz", n.getNodeValue());
}

From source file:ru.codeinside.gws.crypto.cryptopro.CryptoProvider.java

/**
 * ? ./*from w  w w  . j  a  v a2  s  .c  o m*/
 */
private static void fixWsuId(final Node node, final DOMValidateContext ctx, final Set<String> ids) {
    if (node instanceof Element) {
        final NamedNodeMap attributes = node.getAttributes();
        if (attributes != null) {
            final Node wsuId = attributes.getNamedItemNS(WSU, "Id");
            if (wsuId != null) {
                final String id = wsuId.getNodeValue();
                if (ids.contains(id)) {
                    throw new RuntimeException(
                            "? ? " + node + " @" + wsuId);
                }
                ids.add(id);
                ctx.setIdAttributeNS((Element) node, WSU, "Id");
            }
        }
    }
    final NodeList children = node.getChildNodes();
    if (children != null) {
        for (int i = 0; i < children.getLength(); i++) {
            fixWsuId(children.item(i), ctx, ids);
        }
    }
}

From source file:test.framework.TestBase.java

/**
 * Return the text value of the selected attribute considering namespaces.
 * /*  ww w  . j a  v a2  s .c o  m*/
 * @param node The node.
 * @param xPath The xpath to select the node containing the attribute.
 * @param attributeNamespaceURI The namespace URI of the attribute.
 * @param attributeLocalName The local name of the attribute.
 * @return The value for the given attribute.
 * @throws Exception
 */
protected static String getAttributeValueNS(final Node node, final String xPath,
        final String attributeNamespaceURI, final String attributeLocalName) throws Exception {
    String result = null;
    NodeList nodeList = selectNodeList(node, xPath);
    assertTrue(nodeList.getLength() == 1);
    Node hitNode = nodeList.item(0);
    if (hitNode.hasAttributes()) {
        NamedNodeMap nnm = hitNode.getAttributes();
        Node attrNode = nnm.getNamedItemNS(attributeNamespaceURI, attributeLocalName);
        result = attrNode.getTextContent();
    }
    return result;
}