使用WSIL文件读取javaxml
目前,我正在尝试编写一个能够呈现xml文件链接的程序。我使用Jsoup,我当前的代码如下使用WSIL文件读取javaxml,java,xml,jsoup,Java,Xml,Jsoup,目前,我正在尝试编写一个能够呈现xml文件链接的程序。我使用Jsoup,我当前的代码如下 public static String XmlReader() { InputStream is = RestService.getInstance().getWsilFile(); try { Document doc = Jsoup.parse(fis, null, "", Parser.xmlParser()); } catch (Exception e)
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&objname=II_QUERY_PROJECT_IN&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&saml2=disabled" referencedNamespace="http://schemas.xmlsoap.org/wsdl/"/>
</wsil:service>
我该怎么做
谢谢如果只有一个标签
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");
doc.outputSettings().escapeMode(escapeMode.xhtml);System.out.println(doc.select(“wsil | description”).attr(“location”);谢谢你,我还有一个问题,我怎么能从某个选择中得到这个,因为这里是查询项目,但现在还有其他项目。。。在XML文件中,如何对其进行过滤?System.out.println(doc.select(“wsil | name:contains(queryprojects)”).first().parent().select(“wsil | description”).attr(“location”);
String val = doc.select("wsil|name:contains(Query Projects)").first().parent().select("wsil|description").attr("location");