Here you can find the source of getFirstChildElmtByTag(String aTagName)
Parameter | Description |
---|---|
aTagName | a parameter |
public Element getFirstChildElmtByTag(String aTagName)
//package com.java2s; /******************************************************************************* * Copyright (c) 2011 www.isandlatech.com (www.isandlatech.com) * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors:/*from w ww.j av a 2 s.c o m*/ * ogattaz (isandlaTech) - initial API and implementation *******************************************************************************/ import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; public class Main { private Document pDom = null; /** * @param aNode * @param aTagName * @return */ public static Element getFirstChildElmtByTag(Node aNode, String aTagName) { if (aNode == null) { return null; } Node wNode = aNode.getFirstChild(); if (wNode == null || (wNode.getNodeType() == Node.ELEMENT_NODE && wNode .getNodeName().equals(aTagName))) { return (Element) wNode; } else { return getFirstSiblingElmtByTag(wNode, aTagName); } } /** * @param aTagName * @return */ public Element getFirstChildElmtByTag(String aTagName) { return getFirstChildElmtByTag(this.getRootElmt(), aTagName); } /** * @param aNode * @param aTagName * @return */ public static Element getFirstSiblingElmtByTag(Node aNode, String aTagName) { if (aNode == null) { return null; } Node wNode = aNode.getNextSibling(); while (wNode != null && (wNode.getNodeType() != Node.ELEMENT_NODE || !wNode .getNodeName().equals(aTagName))) { wNode = wNode.getNextSibling(); } return (Element) wNode; } /** * @return */ public Element getRootElmt() { return getDom().getDocumentElement(); } /** * @return */ public Document getDom() { return pDom; } }