Java XML Element Get getElementText(Document owner, String elementName, String nsURI)

Here you can find the source of getElementText(Document owner, String elementName, String nsURI)

Description

Returns the text value of the given element name in the CyberSource namespace.

License

Open Source License

Parameter

Parameter Description
owner Document object to search.
elementName local name to search for.
nsURI namespaceURI to used (may be null).

Return

the text value of the given element name in the CyberSource namespace or null if none is found.

Declaration

public static String getElementText(Document owner, String elementName, String nsURI) 

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.NodeList;

public class Main {
    /**/*w  ww.  j a v  a  2s.  com*/
     * Returns the text value of the given element name in the CyberSource
     * namespace.
     *
     * @param owner       Document object to search.
     * @param elementName local name to search for.
     * @param nsURI       namespaceURI to used (may be null).
     * @return the text value of the given element name in the CyberSource
     *         namespace or <code>null</code> if none is found.
     */
    public static String getElementText(Document owner, String elementName, String nsURI) {
        Element elem = getElement(owner, elementName, nsURI);
        if (elem != null) {
            return (elem.getFirstChild().getNodeValue());
        }

        return (null);
    }

    /**
     * Returns the Element object corresponding to the given element name.
     *
     * @param owner       Document object to search.
     * @param elementName local name to search for.
     * @param nsURI       namespaceURI to used (may be null).
     * @return the Element object corresponding to the given element name or
     *         <code>null</code> if none is found.
     */
    public static Element getElement(Document owner, String elementName, String nsURI) {
        NodeList nodes = nsURI != null ? owner.getElementsByTagNameNS(nsURI, elementName)
                : owner.getElementsByTagName(elementName);

        if (nodes != null && nodes.getLength() > 0) {
            return ((Element) nodes.item(0));
        }

        return (null);
    }
}

Related

  1. getElementsByTagName(Element node, String xmlns, String nodeName)
  2. getElementsByTagNameNS1(Element element, String nsName, String tagName)
  3. getElementsByTagNameNS1(Element element, String nsName, String tagName)
  4. getElementsByXpath(Document docInput, String xPath)
  5. getElementsWithName(Document doc, String name)
  6. getElementWithKeyFromDocument(final Document document, final String key)