我在解码 SOAP 信封时遇到问题。这是我的 XML
<?xml version="1.0"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:tns="http://c.com/partner/">
<env:Header>c
<tns:MessageId env:mustUnderstand="true">3</tns:MessageId>
</env:Header>
<env:Body>
<GetForkliftPositionResponse xmlns="http://www.c.com">
<ForkliftId>PC006</ForkliftId>
</GetForkliftPositionResponse>
</env:Body>
</env:Envelope>
我使用以下代码来解码正文,但它总是返回到命名空间 tns:MessageID,而不是返回到 env:body。我还想将 XMLStreamReader 转换为字符串以解决调试问题,可以吗?
XMLInputFactory xif = XMLInputFactory.newFactory();
xif.setProperty("javax.xml.stream.isCoalescing", true); // decode entities into one string
StringReader reader = new StringReader(Message);
String SoapBody = "";
XMLStreamReader xsr = xif.createXMLStreamReader( reader );
xsr.nextTag(); // Advance to header tag
xsr.nextTag(); // advance to envelope
xsr.nextTag(); // advance to body