Here you can find the source of xmlFirstChild(final Element parent, final String childName, final boolean isThrow)
Parameter | Description |
---|---|
parent | the parent |
childName | the child name |
isThrow | the is throw |
public static final Element xmlFirstChild(final Element parent, final String childName, final boolean isThrow)
//package com.java2s; /**//from w w w . j a v a2 s .c o m * Copyright (C) 2011-2012 Barchart, Inc. <http://www.barchart.com/> * * All rights reserved. Licensed under the OSI BSD License. * * http://www.opensource.org/licenses/bsd-license.php */ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /** * Xml first child. * * @param parent * the parent * @param childName * the child name * @param isThrow * the is throw * @return the element */ public static final Element xmlFirstChild(final Element parent, final String childName, final boolean isThrow) { final NodeList nodeList = parent.getChildNodes(); if (nodeList == null) { if (isThrow) { throw new IllegalArgumentException("nodeList == null"); } return null; } final int size = nodeList.getLength(); for (int k = 0; k < size; k++) { final Node child = nodeList.item(k); if (child.getNodeName().equalsIgnoreCase(childName)) { return (Element) child; } } if (isThrow) { throw new IllegalArgumentException("child node not found"); } return null; } }