XMLConfiguration 的使用

  • Post author:
  • Post category:其他



XMLConfiguration xmlConfig  = new XMLConfiguration(“config.xml”);

String STYLE = xmlConfig.getString(“decorate.style”);

String NUM = xmlConfig.getString(“decorate.num”);

String command =”AAA”;

String xpath =”hosts/host[command = ‘”+ command +”‘]/url”;

xmlConfig.setExpressionEngine(new XPathExpressionEngine());

String url  =   xmlConfig.getString(“url”);

配置文件:Class/config.xml:

<?xml  version=”1.0″  encoding=”UTF-8″?>

<!– const.xml –>

<config>



<!– 指 分隔符 –>



<decorate>



<style>/</style>



</decorate>






<!– 指令主机配置 –>



<hosts>



<host>



<url>127.0.0.1</url>



<command>AAA</command>



</host>



<host>



<url>192.168.2.111</url>



<command>BBB</command>



</host>



</hosts>

</config>



版权声明:本文为sudyguoguo原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。