List of usage examples for org.w3c.dom Node getFirstChild
public Node getFirstChild();
From source file:Main.java
public static String getChildValue(Node node) throws DOMException { Node child = node.getFirstChild(); if (child != null) { String val = child.getNodeValue(); if (val.toUpperCase().startsWith("[CDATA")) { val = val.substring(7, val.length() - 2); }/* ww w . j a v a2 s . c o m*/ return val; } else return "NULL"; }
From source file:Main.java
public static Node firstElementNodeChild(Node n) { Node m = n.getFirstChild(); while (m != null && !isElementNode(m)) m = m.getNextSibling();//from w ww. j a v a 2s.com return m; }
From source file:Main.java
/** * Extracts the text from inside the given node * @param node The node to extract from//from ww w .ja va2s. c om * @return the extracted text */ public static String getNodeTextValue(final Node node) { return node.getFirstChild().getNodeValue(); }
From source file:Main.java
public static void setFirst(Node parent, Node node) { Node first = parent.getFirstChild(); if (first != null) parent.insertBefore(node, first); else/*from w w w. ja v a2 s . c o m*/ parent.appendChild(node); }
From source file:Utils.java
/** * Search for a named child of a given node * @param currentNode Starting point for our search * @param tagName Node name to look up//from w ww . j a v a 2 s . c o m * @return matching Node (null if none) */ public static Node getChildSiblingByName(Node currentNode, String tagName) { Node node = currentNode.getFirstChild(); while ((node != null) && (!node.getNodeName().equals(tagName))) { node = node.getNextSibling(); } return node; }
From source file:Main.java
/** * Utility method to fetch the value of the element node * @param node/* w w w. j a va2s . c o m*/ * @return */ public static String getNodeValue(Node node) { for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) { if (child.getNodeType() == Node.TEXT_NODE) { return child.getNodeValue(); } } return null; }
From source file:Main.java
/** * Extracts the actual header node. This should be updated with each * API update that changes the header object, such as "RequestHeader". * * @param soapHeader the soap header//from ww w .j a v a 2 s . co m * @return the {@code Node} that contains elements such as "email" and * "clientEmail" */ public static Node extractRequestHeaderNode(Node soapHeader) { if (soapHeader != null && soapHeader.getFirstChild() != null && soapHeader.getFirstChild().getLocalName().equals("RequestHeader")) { return soapHeader.getFirstChild(); } else { return soapHeader; } }
From source file:Main.java
/** * Gets the first child Element of the node, skipping any Text nodes such as whitespace. * //from ww w . j a va2 s.c o m * @param n The parent in which to search for children * @return The first child Element of n, or null if none */ public static Element getFirstChildElement(Node n) { Node child = n.getFirstChild(); while (child != null && child.getNodeType() != Node.ELEMENT_NODE) { child = child.getNextSibling(); } if (child != null) { return (Element) child; } else { return null; } }
From source file:Main.java
/** Takes the parsed XML representation (i.e. Document) and a string (e.g <variable> in a <query> message) * @param document - the parsed XML represenation * @param tagName - the name of the data item whose value is desired * @return The string that is that value*/ public static String GetValueForNode(Document document, String tagName) { NodeList nodes = document.getElementsByTagName(tagName); if (nodes == null) return (null); else {//from w ww . j a v a 2 s .com Node n = nodes.item(0); String value = n.getFirstChild().getNodeValue(); if (value == null) return null; else return value.trim(); } }
From source file:Main.java
/** * Removes all children of the specified node. * //from w w w.ja va2s . co m * @param node * the node. */ public static void removeAllChildren(final Node node) { Node child; while ((child = node.getFirstChild()) != null) { node.removeChild(child); } }