Here you can find the source of ReadXMLFile3(String in_FileName, String in_TagName)
public static String ReadXMLFile3(String in_FileName, String in_TagName) throws Exception
//package com.java2s; //License from project: Open Source License import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; public class Main { public static String ReadXMLFile3(String in_FileName, String in_TagName) throws Exception { String strOut = ""; DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(in_FileName); Element root = doc.getDocumentElement(); NodeList books = root.getChildNodes(); if (books != null) { for (int i = 0; i < books.getLength(); i++) { Node book = books.item(i); if (book.getNodeType() == Node.ELEMENT_NODE) { if (book.getNodeName().equals(in_TagName)) { strOut = book.getFirstChild().getNodeValue(); }//from w ww.j a v a 2s . c o m } } } return strOut; } }