Java Utililty Methods XML Node Text Value

List of utility methods to do XML Node Text Value

Description

The list of methods to do XML Node Text Value are organized into topic(s).

Method

StringgetNamespaceURIFromPrefix(Node context, String prefix)
Given a prefix and a node, return the namespace URI that the prefix has been associated with.
short nodeType = context.getNodeType();
Node tempNode = null;
switch (nodeType) {
case Node.ATTRIBUTE_NODE: {
    tempNode = ((Attr) context).getOwnerElement();
    break;
case Node.ELEMENT_NODE: {
...
StringgetNodeText(final Node node)
Return the contained text within an Element.
NodeList nl = node.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
    Node c = nl.item(i);
    if (c instanceof Text)
        return ((Text) c).getData();
return null;
StringgetNodeText(Node node)
get Node Text
if (node == null) {
    return null;
String result = "";
NodeList childList = node.getChildNodes();
for (int i = 0; i < childList.getLength(); ++i) {
    Node child = childList.item(i);
    if (child.getNodeName().equals("#text")) {
...
StringgetNodeText(Node node)
get Node Text
NodeList fstNm = ((Element) node).getChildNodes();
String ret = fstNm.item(0).getNodeValue();
return ret;
StringgetNodeText(Node node)
get Node Text
if (node.getNodeType() == Node.ELEMENT_NODE) {
    NodeList childNodes = node.getChildNodes();
    StringBuffer buffer = new StringBuffer();
    for (int i = 0; i < childNodes.getLength(); i++) {
        if (childNodes.item(i).getNodeType() == Node.TEXT_NODE) {
            Node myNode = childNodes.item(i);
            buffer.append(myNode.getNodeValue());
    return buffer.toString();
return "";
StringgetNodeText(Node node)
get Node Text
try {
    return node.getTextContent();
} catch (DOMException ex) {
    return null;
StringgetNodeText(Node node)
get Node Text
switch (node.getNodeType()) {
case Node.ELEMENT_NODE:
    NodeList childNodes = node.getChildNodes();
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node child = childNodes.item(i);
        if (child.getNodeType() == Node.TEXT_NODE) {
            sb.append(child.getNodeValue());
...
StringgetNodeText(Node node)
Extracts to text from the supplied node and it's children.
if (node == null || !node.hasChildNodes())
    return "";
StringBuilder result = new StringBuilder();
NodeList list = node.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
    Node subnode = list.item(i);
    if (subnode.getNodeType() == Node.TEXT_NODE) {
        result.append(subnode.getNodeValue());
...
StringgetNodeText(Node t)
get Node Text
if ((t == null) || (t.getNodeType() != org.w3c.dom.Node.ELEMENT_NODE))
    return null;
NodeList children = t.getChildNodes();
String text = "";
for (int c = 0; c < children.getLength(); c++) {
    Node child = children.item(c);
    if ((child.getNodeType() == org.w3c.dom.Node.TEXT_NODE)
            || (child.getNodeType() == org.w3c.dom.Node.CDATA_SECTION_NODE))
...
StringgetNodeText(org.w3c.dom.Node node)
get Node Text
StringBuffer propertyTextBuffer = new StringBuffer();
org.w3c.dom.NodeList children = node.getChildNodes();
for (int j = 0; j < children.getLength(); j++) {
    org.w3c.dom.Node childNode = children.item(j);
    if (childNode instanceof org.w3c.dom.CDATASection) {
        propertyTextBuffer.append(((org.w3c.dom.CDATASection) childNode).getData());
    } else if (childNode instanceof org.w3c.dom.Text) {
        propertyTextBuffer.append(((org.w3c.dom.Text) childNode).getData().trim());
...