Java XML Read with WSIL file



目前我正在尝试编写一个能够呈现xml文件链接的程序。我用Jsoup,我目前的代码如下

public static String XmlReader() {
InputStream is = RestService.getInstance().getWsilFile();
try {
Document doc = Jsoup.parse(fis, null, "", Parser.xmlParser());
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}

我想从XML文件中读取以下部分:

<wsil:service>
<wsil:abstract>Read the full documentation on: https://host/sap/bc/mdrs/cdo?type=psm_isi_r&amp;objname=II_QUERY_PROJECT_IN&amp;saml2=disabled</wsil:abstract>
<wsil:name>Query Projects</wsil:name>
<wsil:description location="host/sap/bc/srt/wsdl/srvc_00163E5E1FED1EE897C188AB4A5723EF/wsdl11/allinone/ws_policy/document?sap-vhost=host&amp;saml2=disabled" referencedNamespace="http://schemas.xmlsoap.org/wsdl/"/>
</wsil:service>

我想以字符串形式返回以下网址

host/sap/bc/srt/wsdl/srvc_00163E5E1FED1EE897C188AB4A5723EF/wsdl11/allinone/ws_policy/document?sap-vhost=host&amp;saml2=disabled

我该怎么做?

谢谢

> 如果只有一个标签wsil:description那么您可以使用以下代码:

doc.outputSettings().escapeMode(EscapeMode.xhtml);
String val = doc.select("wsil|description").attr("location"); 

应该更改转义模式,因为您处理的不是常规 html,而是 xml。

如果您有多个具有给定名称的标签,则可以搜索不同的相邻元素,并找到与之相关的所需标签:

String val = doc.select("wsil|name:contains(Query Projects)").first().parent().select("wsil|description").attr("location"); 

最新更新