码迷,mamicode.com
首页 > 编程语言 > 详细

[Java] 通过XPath获取XML中某个节点的属性

时间:2016-02-15 12:08:18      阅读:1129      评论:0      收藏:0      [点我收藏+]

标签:

public String getPAUrl(){
		String PAUrl = "";

		try {
			String filePath = System.getProperty ("user.dir").toString()+"/src/test/resources/config/environment.xml";
			logger.info("The path of environment.xml is : "+filePath);
			File file = new File(filePath);
			SAXReader saxReader = new SAXReader();
			Document document = saxReader.read(file);
			String currentEnv = Util.getEnvStr();
			Element el =XmlUtil.getSingleElement(document, "/root/environment[@type=‘" + currentEnv + "‘]/PAUrl");
			PAUrl = XmlUtil.getElementValue(el, "No default PA URL");
			logger.info("PA Url : "+PAUrl);
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		
		return PAUrl;
	}

  

[Java] 通过XPath获取XML中某个节点的属性

标签:

原文地址:http://www.cnblogs.com/MasterMonkInTemple/p/5190229.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!