标签:
构造函数:
public AppTestData(File xmlFile) throws Exception { file = xmlFile; try { saxReader = new SAXReader(); saxReader.setEncoding("UTF-8"); doc = saxReader.read(this.file); init(); } catch (Exception ex) { throw new Exception("Open xml file " + xmlFile.getAbsolutePath() + " failed with error:" + ex.getMessage()); } }
初始化方法:
private void init() { // =========Set account data========= Node node = doc.selectSingleNode("//Account/User1"); sUser1 = node.valueOf("@User"); sUserName1 = node.valueOf("@Name"); sPwd1 = node.valueOf("@PWD"); sJGTUser1 = node.valueOf("@JGT"); sJGTName1 = node.valueOf("@JGTName"); sJGTPwd1 = node.valueOf("@JGTPWD"); sJGTTSFPWD1 = node.valueOf("@JGTTSFPWD"); sHarborName1 = node.valueOf("@hName"); sDomain1 = node.valueOf("@domain"); }
xml数据文件:
<?xml version="1.0" encoding="utf-8" ?> <TestData> <Account> <User1 User="test16" Name="Auto16" PWD="123456abc" JGT="" JGTName="ssss123456" JGTPWD="888@@@" JGTTSFPWD="888@@@" hName="Auto-User1" domain="AutoUser1" desc="" /> <User2 User="test30" Name="AutoTest" PWD="123456abc" JGT="" JGTName="ssss123456" JGTPWD="888@@@" JGTTSFPWD="888@@@" hName="Auto-User2" domain="AutoUser2" desc="" /> </Account> </TestData>
标签:
原文地址:http://www.cnblogs.com/lgm1999/p/4794041.html