2016-02-22 87 views
0

請幫我將下面的SOAP請求數據轉換爲java Collection,我已經嘗試過但沒有得到預期的結果。在第二部分中,您可能會看到下面的參考資料,我已經從Java轉換爲SOAP請求。將SOAP multiref轉換爲java對象

<multiRef id="id1" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:Map" xmlns:ns2="http://xml.apache.org/xml-soap" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"> 
       <item> 
        <key xsi:type="soapenc:string">orderIncrementId</key> 
        <value xsi:type="soapenc:string">ORD-4426</value> 
       </item> 
       <multiRef href="#id3"/> 
      </multiRef> 

      <multiRef id="id3" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns3:Map" xmlns:ns3="http://xml.apache.org/xml-soap" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"> 
       <item> 
        <key xsi:type="soapenc:string">order_item_id</key> 
        <value xsi:type="soapenc:string">1229</value> 
       </item> 
       <item> 
        <key xsi:type="soapenc:string">qty</key> 
        <value xsi:type="soapenc:string">1</value> 
       </item> 
      </multiRef> 

以下xml生成的java如下所述。

Map<String, String> header = new HashMap<String, String>(); 
header.put("OrderIncrementId", "ORD-4426"); 

Map<String, String> detail_1= new HashMap<String, String>(); 
details.put("order_item_id", "1229"); 
details.put("qty", "1"); 

List<Map<String,String>> details = new ArrayList<Map<String,String>>(); 
details.add(detail_1); 

List<Object> finalList = new ArrayList<Objec>(); 
finalList.add(header); 
finalList.add(details); 

<multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" soapenc:arrayType="xsd:anyType[2]" xsi:type="soapenc:Array" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"> 
      <multiRef href="#id1"/> 
      <multiRef href="#id2"/> 
     </multiRef> 
     <multiRef id="id2" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" soapenc:arrayType="xsd:anyType[1]" xsi:type="soapenc:Array" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"> 
      <multiRef href="#id3"/> 
     </multiRef> 
     <multiRef id="id1" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:Map" xmlns:ns2="http://xml.apache.org/xml-soap" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"> 
      <item> 
       <key xsi:type="soapenc:string">orderIncrementId</key> 
       <value xsi:type="soapenc:string">ORD-4426</value> 
      </item> 
     </multiRef> 
     <multiRef id="id3" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns3:Map" xmlns:ns3="http://xml.apache.org/xml-soap" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"> 
      <item> 
       <key xsi:type="soapenc:string">order_item_id</key> 
       <value xsi:type="soapenc:string">1229</value> 
      </item> 
      <item> 
       <key xsi:type="soapenc:string">qty</key> 
       <value xsi:type="soapenc:string">1</value> 
      </item> 
     </multiRef> 

回答

0

我不認爲任何直接的答案可用於您的問題。
但是你可以試試Jaxb(因爲multi ref是一個xml)。你應該能夠轉換成Java對象,並從那裏你可以提取任何需要的對象。

+0

嗨Kartik,請再看一遍。我更新了我的問題。 – Bibhaw