Here you can find the source of getElementByName(Document document, String name)
Parameter | Description |
---|---|
document | a parameter |
name | a parameter |
public static String getElementByName(Document document, String name)
//package com.java2s; /* $This file is distributed under the terms of the license in /doc/license.txt$ */ import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { /**//from ww w . ja va 2 s. c o m * @param document * @param name * @return */ public static String getElementByName(Document document, String name) { NodeList nodes = document.getElementsByTagName(name); String s = null; for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); s = node.getTextContent().trim(); } return s; } }