0
我想從XML文件讀取數據。我正在使用Selenium WebDriver Java &。我在研究過程中找到了許多解決方案。問題似乎沒有適用於我的問題。讀取硒中的xml數據
我的XML文件是這樣:
<Enviroment>
<Parameter>Test_Url</Parameter>
<value>https://www.google.com</value>
<Parameter>Distributed_Test</Parameter>
<value>no</value>
<Parameter>Result_Name</Parameter>
<value>Google_Results</value>
</Enviroment>
我使用讀取此xml文件的代碼是在這裏。
public class ReadXML {
static String value;
public static void main(String[] args) throws FileNotFoundException,IOException {
File file = new File("path of the file");
FileInputStream fileInput =new FileInputStream(file);
Properties prop =new Properties();
//prop.load(fileInput);
prop.loadFromXML(fileInput);
fileInput.close();
Enumeration enumKeys=prop.keys();
while(enumKeys.hasMoreElements()){
//String node = "Environment";
String subnode= "Parameter";
if(((String) enumKeys.nextElement()).contains(subnode)){
value = prop.getProperty(subnode);
System.out.println(value);
}
}
return ;
}
在我使用
prop.load(fileInput)
,輸出打印爲null
三次三個參數值,相信。但是,如果我使用
prop.loadFromXML(fileInput)
,InvalidPropertiesFormatException
顯示。
請幫助..謝謝!
XML文件的根標籤= 「環境」。但是在你的代碼中,你需要尋找:「環境」。有錯誤 –
謝謝.. @ Mahsum我糾正了,但它仍然顯示輸出爲'null' –
您呈現的xml文件是否正確?當我運行它,得到不同的錯誤關於無效? –