show节点元素值解析soap响应显示为null

7eumitmz  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(172)

我有一个soap响应

String responseBody= "<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body> 
 <DisplayCashTransactionForPayingResponse xmlns="http://tempuri.org/"> 
 <DisplayCashTransactionForPayingResult 
  xmlns:a="http://schemas.datacontract.org/2004/07/URemitWCFLib.Receive" 
   xmlns:i="http://www.w3.org/2001/XMLSchema-instance"><a:AmountToPay>3063.000000</a:AmountToPay> 
 <a:AmountToPayInWords>Three Thousand Sixty Three Only</a:AmountToPayInWords> 
 <a:ReceiveCountryCode>BD</a:ReceiveCountryCode><a:ReceiveCurrencyCode>BDT</a:ReceiveCurrencyCode> 
 <a:ReceiverAddress/><a:ReceiverCity>BRAHMANBARIA</a:ReceiverCity> 
    <a:ReceiverContactNo>8808740466050</a:ReceiverContactNo><a:ReceiverFirstName>MOHAMMED MUNASIR</a:ReceiverFirstName>
      <a:ReceiverFourthName>AHMEDULLAH KHAN</a:ReceiverFourthName>
             <a:ReceiverLastName>NASSIR S</a:ReceiverLastName><a:ReceiverMiddleName>BANERR ASHIQ</a:ReceiverMiddleName>
           <a:ReceiverNationality>BD</a:ReceiverNationality>
     <a:RequestDateTime>11/25/2020 08:41:04 GMT</a:RequestDateTime> 
<a:ResponseCode>01</a:ResponseCode>
<a:ResponseDateTime>11/25/2020 08:41:04 GMT</a:ResponseDateTime>
<a:ResponseMessage>Successful API Call</a:ResponseMessage>
<a:SendCountryCode>AE</a:SendCountryCode>
    <a:SendCurrencyCode i:nil="true"/><a:SenderAddress>ABU 2078 NASSIR DUBAI BUR UAE</a:SenderAddress> 
      <a:SenderCity>DUBAI</a:SenderCity><a:SenderContactNo i:nil="true"/> 
         <a:SenderFirstName>FARHAN</a:SenderFirstName><a:SenderFourthName/> 
          <a:SenderIDNumber>7850004154</a:SenderIDNumber><a:SenderIDType>EMIRATES ID</a:SenderIDType><a:SenderLastName>AZIM</a:SenderLastName>
       <a:SenderMiddleName/><a:SenderNationality>BD</a:SenderNationality>
        <a:Status>UnPaid</a:Status>
         <a:Successful>true</a:Successful>
       <a:TransactionDate>10/11/2020</a:TransactionDate>
       <a:TransactionNo>2329142523885</a:TransactionNo>
        </DisplayCashTransactionForPayingResult>
       </DisplayCashTransactionForPayingResponse>
      </s:Body>
              </s:Envelope>"

我想获取节点的值(sendercity、sendermiddlename、sendcountrycode..和所有剩余的字段值),但soap响应正文显示为null,我的代码为

MimeHeaders header = new MimeHeaders();     
           header.addHeader("Content-Type", "text/xml");

            MessageFactory factory = MessageFactory.newInstance();
         InputStream is = new ByteArrayInputStream(responseBody.getBytes());
         SOAPMessage soapMessage = factory.createMessage(header,is);

        SOAPBody body = soapMessage.getSOAPBody();
        NodeList nodes = body.getElementsByTagName("DisplayCashTransactionForPayingResult");
        System.out.println("jjjjjjjjjjjjjj"+nodes.toString());
        // check if the node jjjjjjjjjjjjjjexists and get the value
        String someMsgContent = null;

但结果为空..请帮助获取节点元素和值。请帮忙

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题