Java XML Node Text Value hasNodeText(Node n)

Here you can find the source of hasNodeText(Node n)

Description

Boolean testing whether or not the node in question is an Element with a single child text node.

License

Open Source License

Declaration

public static boolean hasNodeText(Node n) 

Method Source Code


//package com.java2s;
import org.w3c.dom.Node;

public class Main {
    /**//from  w  w  w . jav  a  2s.  co  m
       Boolean testing whether or not the node in question is an Element
       with a single child text node.
    */
    public static boolean hasNodeText(Node n) {
        return (n.getNodeType() == Node.ELEMENT_NODE && n.hasChildNodes()
                && n.getFirstChild().getNodeType() == Node.TEXT_NODE && n.getFirstChild().equals(n.getLastChild()));
    }
}

Related

  1. getTextValue(Node node)
  2. getTextValue(Node node)
  3. getTextValue(Node node)
  4. getTrimmedText (final Node node)
  5. getTrimmedTextContent(Node element)
  6. hasOnlyTextSiblings(@Nonnull Node node)
  7. hasTextContent(final Node node)
  8. hasTextContent(Node n)