如何在Java中获取xml的属性值。我接收了一个xml字符串并想要一个特定的值

时间:2017-04-15 17:15:14

标签: java xml

我只想要app_id“Rahul2测试”。

我没有将这个xml存储在文件中,我怎么能得到它?

代码:

String s=resultWrapper.getAppBuilds();      
System.out.println(s);

输出:

<application app_name="Rahul1 Test" app_id="18" >
<customfield name="Custom 1" value=""/>
<customfield name="Custom 2" value=""/>
<customfield name="Custom 3" value=""/>
<customfield name="Custom 4" value=""/>
<customfield name="Custom 5" value=""/>
<customfield name="Custom 6" value=""/>
<customfield name="Custom 7" value=""/>
<customfield name="Custom 8" value=""/>
<customfield name="Custom 9" value=""/>
<customfield name="Custom 10" value=""/>
<build version>
</build>
</application>
<application app_name="Rahul2 Test" app_id="196" >
<customfield name="Custom 1" value=""/>
<customfield name="Custom 2" value=""/>

1 个答案:

答案 0 :(得分:0)

将String转换为DOM xml(https://stackoverflow.com/a/3906936/58082),然后使用XPATH获取属性(How to get attribute value using XPath in Java?