我有SOAP请求XML,我想从中找到方法名称。我使用了以下代码,但SOAP Body总是声明为null,如果我有Soap Body,那么imediate的下一个子将是Method名称。怎么解决这个问题?
String xml1 = "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"+
"<soap:Body>"+
"<ConversionRate xmlns=\"http://www.webserviceX.NET/\">"+
"<FromCurrency>AFA</FromCurrency>"+
"<ToCurrency>TRY</ToCurrency>"+
"</ConversionRate>"+
"</soap:Body>"+
"</soap:Envelope>";
InputStream is = new ByteArrayInputStream(xml1.getBytes());
SOAPMessage soapMessage = MessageFactory.newInstance().createMessage(null, is);
SOAPBody body = soapMessage.getSOAPBody();
System.out.println(body);
答案 0 :(得分:0)
找到答案。
body.getChildNodes().item(0).getNodeName()
这将给出方法名称