Here you can find the source of ReadXMLFile1(String in_FileName, String in_TagName)
Parameter | Description |
---|---|
in_FileName | a parameter |
in_TagName | a parameter |
Parameter | Description |
---|---|
Exception | an exception |
public static String ReadXMLFile1(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.NodeList; public class Main { /**/* ww w. jav a 2 s. c o m*/ * * @param in_FileName * @param in_TagName * @return * @throws Exception */ public static String ReadXMLFile1(String in_FileName, String in_TagName) throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(in_FileName); Element root = doc.getDocumentElement(); return GetParStrValue(root, in_TagName); } public static String GetParStrValue(Element in_el, String in_ParName) { NodeList fields = in_el.getElementsByTagName(in_ParName); String m_value = ""; if (fields.getLength() == 1) { if (fields.item(0).getFirstChild() != null) { m_value = fields.item(0).getFirstChild().getNodeValue(); } } if (m_value == null) { m_value = ""; } return m_value; } }