如何使用pl / sql解析具有href标记的soap响应

时间:2013-02-13 03:51:30

标签: xml soap plsql xml-parsing

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

还有一件事是这个肥皂响应值改变了每个请求中的序列。

<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>

1 个答案:

答案 0 :(得分: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;