【问题标题】:pasring xml response from a soap webservice to save in table解析来自肥皂网络服务的 xml 响应以保存在表中
【发布时间】:2019-09-07 01:07:51
【问题描述】:

我在 plsql 中调用 Soap 服务,我得到 xml 格式的响应 我想解析 xml 并想在 Oracle 表中保存一个值。 下面的 xml 输出:

<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
   <s:Header>
      <ActivityId xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics" CorrelationId="3c08103b-65da-4f34-95e7-ec2c90ba5b74">00000000-0000-0000-0000-000000000000</ActivityId>
      <o:Security xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" s:mustUnderstand="1">
         <u:Timestamp u:Id="_0">
            <u:Created>2019-04-16T20:21:06.467Z</u:Created>
            <u:Expires>2019-04-16T20:26:06.467Z</u:Expires>
         </u:Timestamp>
      </o:Security>
   </s:Header>
   <s:Body>
      <SaveSalesResponse xmlns="https://unifree.com.tr/services/custom">
         <SaveSalesResult xmlns:a="http://schemas.datacontract.org/2004/07/CustomServiceLibrary.DataContract" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <a:Result>true</a:Result>
            <a:Provision>
               <a:ProvisionNo>245982</a:ProvisionNo>
            </a:Provision>
         </SaveSalesResult>
      </SaveSalesResponse>
   </s:Body>
</s:Envelope>

我想在表格中保存&lt;a:ProvisionNo&gt;245982&lt;/a:ProvisionNo&gt;这个号码 请建议一种在表中存储值的简单方法

【问题讨论】:

  • 谢谢萨米。文档中是否总是只有一个 ,还是会有多个?

标签: sql xml oracle parsing plsql


【解决方案1】:

假设您提供的示例文档代表正在使用的文档布局(即只有一个&lt;s:Body&gt;,只有一个&lt;SaveSalesResponse&gt;,依此类推,每个文档只有一个&lt;a:PorivisionNo&gt;,那么EXTRACTVALUE 就是我们所需要的。

如果您的数据集包含更复杂的结构,每个文档包含多个 &lt;a:ProvisionNo&gt;,我建议改为使用 XMLQUERY/XMLTABLE 提取值。

下面是通过EXTRACTVALUE 加载带有&lt;a:ProvisionNo&gt; 的表的示例。

CREATE TABLE PROVISION_NO(THE_PROVISION_NO INTEGER);

Table created.

然后运行加载:

INSERT INTO PROVISION_NO(THE_PROVISION_NO)
SELECT EXTRACTVALUE( XMLTYPE('<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    <s:Header>
        <ActivityId xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics" CorrelationId="3c08103b-65da-4f34-95e7-ec2c90ba5b74">00000000-0000-0000-0000-000000000000</ActivityId>
        <o:Security xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" s:mustUnderstand="1">
            <u:Timestamp u:Id="_0">
                <u:Created>2019-04-16T20:21:06.467Z</u:Created>
                <u:Expires>2019-04-16T20:26:06.467Z</u:Expires>
            </u:Timestamp>
        </o:Security>
    </s:Header>
    <s:Body>
        <SaveSalesResponse xmlns="https://unifree.com.tr/services/custom">
            <SaveSalesResult xmlns:a="http://schemas.datacontract.org/2004/07/CustomServiceLibrary.DataContract" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
                <a:Result>true</a:Result>
                <a:Provision>
                    <a:ProvisionNo>245982</a:ProvisionNo>
                </a:Provision>
            </SaveSalesResult>
        </SaveSalesResponse>
    </s:Body>
</s:Envelope>'),
    '/s:Envelope/s:Body/*:SaveSalesResponse/*:SaveSalesResult/a:Provision/a:ProvisionNo',
    'xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" xmlns:a="http://schemas.datacontract.org/2004/07/CustomServiceLibrary.DataContract" ')
FROM DUAL;

1 row created.

结果:

SELECT THE_PROVISION_NO FROM PROVISION_NO;

   THE_PROVISION_NO
___________________
             245982

1 row selected.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多