如何检索org.apache.axis.message.MessageElement

时间:2018-11-15 11:11:23

标签: java web-services soap axis2

我正在用肥皂擦洗网络服务。我调用服务,然后返回MessageElement类型。但是我正在使用这些信息。

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <KargoBilgileriByReferansResponse xmlns="http://tempuri.org/">
         <KargoBilgileriByReferansResult>
            <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
               <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
                  <xs:complexType>
                     <xs:choice minOccurs="0" maxOccurs="unbounded">
                        <xs:element name="Table1">
                           <xs:complexType>
                              <xs:sequence>
                                 <xs:element name="name" type="xs:string" minOccurs="0"/>
                                 <xs:element name="surname" type="xs:string" minOccurs="0"/>
                              </xs:sequence>
                           </xs:complexType>
                        </xs:element>
                     </xs:choice>
                  </xs:complexType>
               </xs:element>
            </xs:schema>
            <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
               <NewDataSet xmlns="">
                  <Table1 diffgr:id="Table11" msdata:rowOrder="0">
                     <name>john</name>
                     <surname>doe</surname>
               </Table1>
               </NewDataSet>
            </diffgr:diffgram>
         </KargoBilgileriByReferansResult>
         <pWsError/>
      </KargoBilgileriByReferansResponse>
   </soap:Body>
</soap:Envelope>

这是soap ui响应。例如,我想要名字。如何获取姓名和姓氏值?

此信息类型为MessageElement []数组。

1 个答案:

答案 0 :(得分:0)

您应该使用这种方式。

Node portType = (Node) messageElements[1].getElementsByTagName("NewDataSet").item(0);
NodeList operations = portType.getChildNodes();
NodeList operations2=operations.item(0).getChildNodes();
NodeList operations3=operations2.item(0).getChildNodes(); 
NodeList operations4=operations2.item(1).getChildNodes(); 
System.out.println(operations3.item(0).getParentNode().getNodeName()+" - "+operations3.item(0).getNodeValue()); 
System.out.println(operations4.item(0).getParentNode().getNodeName()+" - "+operations4.item(0).getNodeValue()); 

控制台日志

  • 姓名-约翰
  • 姓-母鹿