Hi All. I Have de followin xml

<s:envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:body>
      <ns2:procesarresponse xmlns:ns2="http://web.app/">
         <return>
            <wsrespuesta xmlns="AstraDTS">
               <coderror>0000</coderror>
               <menerror>Success</menerror>
               <deserror>N/A</deserror>
               <saldosconsulta>
                  <wsrespsaldos.wsrespsaldositem>
                     <biller>jetstereo</biller>
                     <numservicio>1</numservicio>
                     <reference1>0801-1996-03857</reference1>
                     <reference2>0000020052845</reference2>
                     <reference3>6216.92</reference3>
                     <reference4/>
                     <reference5>ANTHONY BAQUEDANO</reference5>
                     <valmon>LPS</valmon>
                     <pagmon>LPS</pagmon>
                     <fecmaxsald>20201009</fecmaxsald>
                     <valores>
                        <wsvalores.wsvaloresitem>
                           <valsnum>01</valsnum>
                           <valsmon>1554.22</valsmon>
                        </wsvalores.wsvaloresitem>
                     </valores>
                  </wsrespsaldos.wsrespsaldositem>
               </saldosconsulta>
            </wsrespuesta>
         </return>
      </ns2:procesarresponse>
   </s:body>
</s:envelope>

And I want to parse it with an stored procedure. The followin is my snniped code.

SELECT *
 FROM      OPENXML (response, '//*:return/wsRespuesta/*')
    WITH ( CodError CHAR (10) 'CodError',
           Biller   CHAR (20) 'Biller',
    ........ all other fields
    ........

           MenError    char(90) 'MenError');
    Select response;

But I'm getting nothing. I will appreciate your help. Thank you in advance.

asked 16 Mar, 00:11

jeffreehy's gravatar image

jeffreehy
31226
accept rate: 0%

edited 16 Mar, 04:48

Volker%20Barth's gravatar image

Volker Barth
37.6k345513778


Here's a starting point with a few remarks:

  • OpenXML supports namespaces, so any element must be specified with its according namespace ("s " and "ns" in your sample) or with the wildcard ("*") if element names do not overlap.
  • XML tags are case-sensitive.
  • In case you do know the expected tags beforehand, you might use XPath expressions for the according elements, as used below. That ways you can select values from different "levels" within the same query. If there are unknown tags, it's better to use OpenXML with its meta-properties like "@mp:localname" to explore the structure of the XML document.
create or replace variable response xml;
set response =
'<s:envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
   <s:body>
      <ns2:procesarresponse xmlns:ns2="http://web.app/">
         <return>
            <wsrespuesta xmlns="AstraDTS">
               <coderror>0000</coderror>
               <menerror>Success</menerror>
               <deserror>N/A</deserror>
               <saldosconsulta>
                  <wsrespsaldos.wsrespsaldositem>
                     <biller>jetstereo</biller>
                     <numservicio>1</numservicio>
                     <reference1>0801-1996-03857</reference1>
                     <reference2>0000020052845</reference2>
                     <reference3>6216.92</reference3>
                     <reference4/>
                     <reference5>ANTHONY BAQUEDANO</reference5>
                     <valmon>LPS</valmon>
                     <pagmon>LPS</pagmon>
                     <fecmaxsald>20201009</fecmaxsald>
                     <valores>
                        <wsvalores.wsvaloresitem>
                           <valsnum>01</valsnum>
                           <valsmon>1554.22</valsmon>
                        </wsvalores.wsvaloresitem>
                     </valores>
                  </wsrespsaldos.wsrespsaldositem>
               </saldosconsulta>
            </wsrespuesta>
         </return>
      </ns2:procesarresponse>
   </s:body>
</s:envelope>';

SELECT *
FROM OPENXML (response, '//*:return/*:wsrespuesta')
   WITH (coderror CHAR (10) '*:coderror',
         menerror CHAR (10) '*:menerror',
         deserror CHAR (10) '*:deserror',
         biller CHAR (10)   '*:saldosconsulta/*:wsrespsaldos.wsrespsaldositem/*:biller');

returns

coderror;menerror;deserror;biller
0000;Success;N/A;jetstereo

permanent link

answered 16 Mar, 05:07

Volker%20Barth's gravatar image

Volker Barth
37.6k345513778
accept rate: 34%

edited 16 Mar, 05:10

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×23
×19

question asked: 16 Mar, 00:11

question was seen: 152 times

last updated: 16 Mar, 05:10