1. Patricia Guzman
  2. PowerBuilder
  3. Friday, 6 October 2023 21:16 PM UTC

Hello community,

I need some help, please.

I got the following xml as SOAP webservice response, and I need to get the values of each of the fields such as cedulaRuc, codigoASP, nombre1, nombre2, etc.

I`m using PBDOM object to parse the XML data. However when I try to get any of the elements, I got a null exception message.

I dont know what I´m doing wrong.

 

string ls_xml_response

 

ls_xml_response = '<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">' + &
'<s:Body>' + &
'<consultaProveedoresResponse xmlns="http://tempuri.org/"'+&
'<consultaProveedoresResult xmlns:a="http://schemas.datacontract.org/2004/07/WcfServiceSCSP.clasesProyecto"'+&
'xmlns:i="http://www.w3.org/2001/XMLSchema-instance">'+&
'<a:lstProveedor>' +&
'<a:proveedor>'+&
'<a:cedulaRuc>1101499999</a:cedulaRuc>'+&
'<a:codigoSAP>0000060155</a:codigoSAP>'+&
'<a:nombre1>SAMANIEGO PUERTAS BRUNO MIGUEL</a:nombre1>'+&
'<a:nombre2/><a:nombre3/><a:nombre4/><a:tipo/></a:proveedor></a:lstProveedor>'+&
'<a:resp i:nil="true"/>'+&
'</consultaProveedoresResult>'+&
'</consultaProveedoresResponse>'+&
'</s:Body>'+&
'</s:Envelope>'

 

//Using PBDOM

PBDOM_Builder         lpbdom_builder
PBDOM_Document    lpbdom_doc

STRING ls_value, ls_error_xml

lpbdom_Builder = CREATE PBDOM_BUILDER

lpbdom_Doc = lpbdom_Builder.BuildFromString( ls_xml_response)  

try

 ls_value = lpbdom_Doc.GetRootElement().&
               GetChildElement("Body", "soap","http://schemas.xmlsoap.org/soap/envelope/").&
                GetChildElement("consultaProveedoresResponse","","http://tempurl.org").&       
                GetChildElement("consultaProveedoresResult","","http://tempurl.org").&
              GetChildElement("lstProveedor").&
              GetChildElement("proveedor").&
             GetChildElement("cedulaRUC").getText()

Catch (PBDOM_Exception lpbdom_Except)
        ls_error_xml = "PBDOM_Exception : " + string(lpbdom_Except.GetExceptionCode())
        RETURN -1
    END TRY
    
    DESTROY(lpbdom_Builder)

 

Thanks in advance

 

Kevin Ridley Accepted Answer Pending Moderation
  1. Monday, 9 October 2023 13:03 PM UTC
  2. PowerBuilder
  3. # 1

I would suggest reading the following and checking out the sample code.  I'd also recommending parsing the xml in steps instead of trying to do it all in 1 long statement.

 

https://community.appeon.com/index.php/articles-blogs/tutorials-articles/2-powerbuilder/131-pbdom-with-powerbuilder

Comment
There are no comments made yet.
René Ullrich Accepted Answer Pending Moderation
  1. Monday, 9 October 2023 14:06 PM UTC
  2. PowerBuilder
  3. # 2

There are a lot of different errors in your code.

 

ls_value = lpbdom_Doc.GetRootElement().&
 						GetChildElement("Body", "s", "http://schemas.xmlsoap.org/soap/envelope/").&
 						GetChildElement("consultaProveedoresResponse","","http://tempuri.org/").&       
						GetChildElement("consultaProveedoresResult","","http://tempuri.org/").&
						GetChildElement("lstProveedor", "a", "http://schemas.datacontract.org/2004/07/WcfServiceSCSP.clasesProyecto").&
						GetChildElement("proveedor", "a", "http://schemas.datacontract.org/2004/07/WcfServiceSCSP.clasesProyecto").&
						GetChildElement("cedulaRuc", "a", "http://schemas.datacontract.org/2004/07/WcfServiceSCSP.clasesProyecto").getText()

 

As kevin already wrote: You should not concatenate the calls.

Comment
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.