【发布时间】:2015-09-30 01:10:18
【问题描述】:
这是我从服务器得到的响应,
虽然我可以获取MM7Version 元素值,但我无法获取Status 元素值。它返回 null。
SoapMeesage XML 响应:
<?xml version='1.0' encoding='UTF-8'?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Header>
<mm7:TransactionID SOAP-ENV:mustUnderstand="1" xmlns:mm7="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-2">TID.BIP_TRASNID.20041103.135200.001</mm7:TransactionID>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<MM7Version>5.6.0</MM7Version>
<Status><StatusCode>2602</StatusCode><StatusText>Invalid status</StatusText></Status>
<MessageID></MessageID>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Java 代码:
SOAPMessage response = connection.call(message, endpoint);
SOAPEnvelope env= response.getSOAPPart().getEnvelope();
SOAPBody sb = env.getBody();
Name ElName = env.createName("Status");
//Get child elements with the name XElement
Iterator it = sb.getChildElements(ElName);
//Get the first matched child element.
//We know there is only one.
SOAPBodyElement sbe = (SOAPBodyElement) it.next();
//Get the value for XElement
String MyValue = sbe.getValue();
System.out.println("MyValue: "+MyValue);
【问题讨论】:
-
重复问题有什么相似之处?我可以获得整个 XML 值。为什么我在获取其他字段时无法检索状态字段? response.writeTo(System.out);用于这个。
标签: java xml web-services soap