<?xmlversion="1.0" encoding="iso-8859-1"?>
<root>
<modulename="tms">
<section name="testdata db">
<param name="ip">X.X.X.X</param>
<param name="port">1433</param>
<param name="auth">sql</param>
<param name="username">sa</param>
<param name="password">XXXX</param>
<param name="database">tms</param>
</section>
<section name="iebrowser">
<param name="class">com.XXXX.mobile.env.IExplorer</param>
<param name="browserName">IE8</param>
<param name="browserType">ie</param>
<param name="browserBinary"></param>
<param name="browserProfile"></param>
</section>
<section name="firefoxbrowser">
<param name="class">com.XXXX.mobile.env.Firefox</param>
<param name="browserName">Firefox16</param>
<param name="browserType">firefox</param>
<param name="browserBinary">C:\Program Files (x86)\Mozilla Firefox\firefox.exe</param>
<paramname="browserProfile">C:\Users\Administrator\AppData\Local\Mozilla\Firefox\Profiles\5ylcw2n0.default</param>
</section>
</module>
</root>
public static Map<String,String> parse(String filename, String section) throws Exception {
Map<String, String> container = new HashMap<String, String>();
File file = new File(filename);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(file);
doc.getDocumentElement().normalize();
NodeList nodeLst = doc.getElementsByTagName("section");
for (int s = 0; s <nodeLst.getLength(); s++){
Node fstNode =nodeLst.item(s);
Element fstElmnt = (Element) fstNode;
if(fstElmnt.getAttribute("name").equals(section)) {
NodeList fstNmElmntLst = fstElmnt.getElementsByTagName("param");
for (int j = 0; j <fstNmElmntLst.getLength(); j++) {
Element fstNmElmnt = (Element) fstNmElmntLst.item(j);
container.put(fstNmElmnt.getAttribute("name"),fstNmElmnt.getTextContent());
}
break;
}
}
return container;
}