Here you can find the source of getChildTextByName(Element parent, String name)
Parameter | Description |
---|---|
parent | parent element |
name | child element name |
public static String getChildTextByName(Element parent, String name)
//package com.java2s; //License from project: Apache License import org.w3c.dom.*; public class Main { /**/* w ww . java 2 s . c om*/ * Equivalent to getTextContent(getFirstChildByName(e, n)), with * a null check. * * @param parent parent element * @param name child element name * @return */ public static String getChildTextByName(Element parent, String name) { Element e = getFirstChildByName(parent, name); return (e != null) ? getTextContent(e) : null; } /** * Return the first child element with a given name. * @param parent parent element * @param name child element name * @return */ public static Element getFirstChildByName(Element parent, String name) { NodeList children = parent.getElementsByTagName(name); if (children.getLength() == 0) { return null; } return (Element) children.item(0); } /** * Returns normalized text content for a node. * @param node * @return text content of child node, trimmed */ public static String getTextContent(Node node) { return node.getTextContent().trim(); } }