这是 SOAP 响应:
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<SearchResponse xmlns="...">
<SearchResult>
<?xml version="1.0" standalone="yes"?> <items blahblahblah1 </items>
<?xml version="1.0" standalone="yes"?> <items blahblahblah2 </items>
</SearchResult>
</SearchResponse>
</soap12:Body>
</soap12:Envelope>
从“SearchResult”中,我想一次获取“项目”的每个完整 xml。我的意思是,我想单独获得一个完整的“items blahblahblah /items”。我怎么做?
这是我想出的使用 DOM 从“SearchResult”中获取所有 xml 的方法,但是如何获取这些项目?
DocumentBuilder db = factory.newDocumentBuilder();
InputSource inStream = new InputSource();
inStream.setCharacterStream(new StringReader(soapResponse));
Document doc = db.parse(inStream);
NodeList nl = doc.getElementsByTagName("SearchResult");
xml = nl.item(0).getFirstChild().getNodeValue();