Java Utililty Methods XML Node Value

List of utility methods to do XML Node Value

  1. HOME
  2. Java
  3. X
  4. XML Node Value

Description

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

Method

String getNodeVal(Node node)
get Node Val
NodeList nl = node.getChildNodes();
for (int i = 0; i < nl.getLength(); ++i) {
 if (nl.item(i).getNodeType() == Node.TEXT_NODE) {
 if (nl != null) {
 String v = ((Text) (nl.item(0))).getData();
 return v;
return null;
String getNodeValue(final Node iNode)
This method gets the text node of an input node.
String value = new String();
if (iNode != null) {
 NodeList children = iNode.getChildNodes();
 int numChildren = children.getLength();
 if (children != null) {
 for (int i = 0; i < numChildren; i++) {
 if ((children.item(i).getNodeType() == Node.TEXT_NODE)
 || (children.item(i).getNodeType() == Node.CDATA_SECTION_NODE)) {
...
String getNodeValue(final Node node)
get Node Value
if (node.getNodeType() == Node.ELEMENT_NODE) {
 Node n = node.getFirstChild();
 if (n != null) {
 do {
 if (n.getNodeType() == Node.TEXT_NODE) {
 return n.getNodeValue();
 } while ((n = n.getNextSibling()) != null);
...
String getNodeValue(final Node node)
Retrieve a DOM node value as a string depending on its type.
String result = "";
if (node == null) {
 return result;
switch (node.getNodeType()) {
case Node.ATTRIBUTE_NODE:
 result = node.getNodeValue();
 break;
...
String getNodeValue(List elements, String nodeName, String defaultValue)
Return the text value of the first child of the named node, or the specified default if the node can't be found.
For example, calling getNodeValue(el, "Mode", "whatever") on a list of elements which contains the following XML: survival should return "survival".
if (elements != null) {
 for (Element el : elements) {
 if (el.getNodeName().equals(nodeName)) {
 if (el.getFirstChild() != null) {
 return el.getFirstChild().getTextContent();
return defaultValue;
String getNodeValue(Node aNode)
------------------------------------------------------------ Gets the String value of a node.
String value = null;
if (aNode.getNodeValue() != null) {
 value = aNode.getNodeValue() != null ? aNode.getNodeValue().trim() : null;
} else {
 NodeList list = aNode.getChildNodes();
 if (list.getLength() == 1) {
 Node child = list.item(0);
 if (child != null) {
...
String getNodeValue(Node fatherNode, String nodeName)
Gets a node's text value given its parent node and the name of the wanted child node.
String value = null;
if (((Element) fatherNode).getElementsByTagName(nodeName) != null) {
 Node node = ((Element) fatherNode).getElementsByTagName(nodeName).item(0);
 value = node.getTextContent();
 if (value != null) {
 value = value.trim();
return value;
String getNodeValue(Node iNode)
This method gets the text node of an input node.
String value = new String();
if (iNode != null) {
 NodeList children = iNode.getChildNodes();
 int numChildren = children.getLength();
 if (children != null) {
 for (int i = 0; i < numChildren; i++) {
 if ((children.item(i).getNodeType() == Node.TEXT_NODE)
 || (children.item(i).getNodeType() == Node.CDATA_SECTION_NODE)) {
...
String getNodeValue(Node iNode)
This method gets the text node of an input node.
String value = new String();
if (iNode != null) {
 NodeList children = iNode.getChildNodes();
 int numChildren = children.getLength();
 if (children != null) {
 for (int i = 0; i < numChildren; i++) {
 if ((children.item(i).getNodeType() == Node.TEXT_NODE)
 || (children.item(i).getNodeType() == Node.CDATA_SECTION_NODE)) {
...
String getNodeValue(Node n)
get Node Value
if (n == null)
 return null;
return n.getTextContent();


AltStyle によって変換されたページ (->オリジナル) /