当我使用SOAP request
发送SAAJ API
时,我会收到一个大的SOAP response
,我需要在其中搜索一些节点。
我正在使用下面的代码,但它只显示了body的第一个节点的名称(HotelListResponse
有很多孩子),我注意到循环只迭代一次,(如注释部分所示)。
简而言之:我需要知道如何在其类型为SOAPMessage的变量中搜索某些节点(最好通过其名称)。感谢
SOAPMessage sm = response; //this is the response
sm.writeTo(System.out); //response is shown successfully in console
SOAPBody ReBody = sm.getSOAPBody();
Iterator sentIt = ReBody.getChildElements(); //create an iterator on elements
int counter=0;
while(sentIt.hasNext())
{
SOAPBodyElement sentSBE = (SOAPBodyElement)sentIt.next();
Iterator sentIt2 = sentSBE.getChildElements();
SOAPElement sentSE = (SOAPElement)sentIt2.next();
String sentID = sentSE.getNodeName(); //result is HotelListResponse
counter++;
//System.out.println("sentID:"+sentID);
}
System.out.println("counter"+counter); //result is 1