0

我想解析下面的肥皂响应。问题出在 tag1 中,它指向一个名为 id1 的 href 链接。所以我们必须去 id1 的响应中获取值。

还有一件事是这个soap响应值是改变每个请求的顺序。

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
    <ns1:getBlock soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://diamondip.com/ipcontrol/ws/">
        <getBlockByIpAddressReturn href="#id0"/>
    </ns1:getBlock>

<multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:WSGenericBlock" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="http://service.ipcontrol.diamondip.com">
    <tag1 href="#id1"/>      
    <tag2 soapenc:arrayType="soapenc:string[1]" xsi:type="soapenc:Array">
        <item xsi:type="soapenc:string">Container1</item>
    </tag2>  
    <tag3 xsi:type="xsd:dateTime">2013-02-01T06:45:32.000Z</tag3>
    <tag4 soapenc:arrayType="soapenc:string[4]" xsi:type="soapenc:Array">
        <item xsi:type="soapenc:string">uf1=221805</item>
        <item xsi:type="soapenc:string">uf2=34531</item>
    </tag4> 
    <tag5 href="#id2"/> 
</multiRef>   
<multiRef id="id1" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:boolean" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">false</multiRef>
<multiRef id="id2" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" lowestSetBit="3" xsi:type="soapenc:integer" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">8</multiRef>
</soapenv:Body>
</soapenv:Envelope>
4

1 回答 1

1

也许这可以给你一个开始(它并不完美,我知道......)

declare

  xl clob := '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"  xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
    <ns1:getBlock soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://diamondip.com/ipcontrol/ws/">
        <getBlockByIpAddressReturn href="#id0"/>
    </ns1:getBlock>

<multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:WSGenericBlock" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="http://service.ipcontrol.diamondip.com">
    <tag1 href="#id1"/>      
    <tag2 soapenc:arrayType="soapenc:string[1]" xsi:type="soapenc:Array">
        <item xsi:type="soapenc:string">Container1</item>
    </tag2>  
    <tag3 xsi:type="xsd:dateTime">2013-02-01T06:45:32.000Z</tag3>
    <tag4 soapenc:arrayType="soapenc:string[4]" xsi:type="soapenc:Array">
        <item xsi:type="soapenc:string">uf1=221805</item>
        <item xsi:type="soapenc:string">uf2=34531</item>
    </tag4> 
    <tag5 href="#id2"/> 
</multiRef>   
<multiRef id="id1" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:boolean" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">false</multiRef>
<multiRef id="id2" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" lowestSetBit="3" xsi:type="soapenc:integer" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">8</multiRef>
</soapenv:Body>
</soapenv:Envelope>';

  v_parser Xmlparser.Parser;
  v_doc    XMLDOM.DOMDocument;
  v_nl     XMLDOM.DOMNodeList;
  v_att    varchar2(300);
  v_refId  varchar2(300);
  v_val    varchar2(300);

begin

  v_parser := Xmlparser.newParser;
  xmlparser.setValidationMode(v_parser, TRUE);

  Xmlparser.parseClob(v_parser, xl);

  v_doc := Xmlparser.getDocument(v_parser);

  v_nl  := xslprocessor.selectNodes(XMLDOM.makeNode(v_doc), '//tag1');
  v_att := XMLDOM.getAttribute((XMLDOM.makeElement(XMLDOM.item(v_nl, 0))),
                               'href');

  v_refId := substr(v_att, 2);

  v_nl := xslprocessor.selectNodes(XMLDOM.makeNode(v_doc),
                                   '//multiRef[@id="' || v_refId || '"]');

  v_val := XMLDOM.getNodeValue(XMLDOM.getFirstChild(XMLDOM.item(v_nl, 0)));

  dbms_output.put_line(v_val);

end;
于 2013-02-13T08:24:37.343 回答