I want to read this xml file:
<configuration>
<parameter name="path">C:\Users\bellibot\Desktop</parameter>
<parameter name="filename">config.xml</parameter>
<module type="livestatus" id="0001">
<parameter name="username">nagiosadmin</parameter>
<parameter name="password">nagiosadmin</parameter>
<parameter name="hostaddress">127.0.0.1/nagios/live.php?q=</parameter>
</configuration>
using this code:
class XMLslave {
XMLConfiguration config;
String defval = "DEFAULT";
public XMLslave(){}
public XMLslave(String path, String filename){
try{
String str = path + "\\" + filename;
File file = new File(path, filename);
this.config = new XMLConfiguration(file);
this.config.setExpressionEngine(new XPathExpressionEngine());
}catch(ConfigurationException e){}
}
public static void main(String[] args) {
try{
BufferedReader in = new BufferedReader(
new InputStreamReader(System.in));
System.out.println("Insert Path");
String path = in.readLine();
System.out.println("Insert Filename");
String filename = in.readLine();
XMLslave slave = new XMLslave(path, filename);
String str = slave.getKey("path");
System.out.println(str);
}catch (IOException e){}
}
String getKey(String key){
String result;
String str = "/configuration/parameter[@name='" + key + "']";
result = this.config.getString(str);
if (result==null){
return this.defval;
}else{
return result;}
}
I don't understand why the return value is "DEFAULT" instead of "C:\Users\bellibot\Desktop", i tested the xpath syntax and it's legal, i belive config.getString() is somehow not working. Thanks for the help.