The purpose of this article is to show you how to use the PBDOM object to build the specified XML content for the parameter of an HTTP request sent with the HTTPClient object and how to obtain the specified content in the returned XML string.

Implementation Steps:

1. Load the PBDOM Object in the PB Application

You can add pbdom170.pbd directly into your application (Default Path: C:\Program Files (x86)\Appeon\Shared\PowerBuilder) or import the PBDOM170.pbx file into a PBL in your application.

2. Use the PBDOM Object to Build the Specified XML String

Open the SOAP Web service on IE as shown below. Copy the associated SOAP sample request. Refer to the red content below. (If you don’t see this content, please contact your service provider to get such a sample request.)


The content of the XML string to be built:

 <?xml version="1.0" encoding="utf-8"?>

 <soap:Envelope xmlns:xsi="" xmlns:xsd="" xmlns:soap="">


     <of_add xmlns="">





If you want to simply use a string to build the XML content and send it through HTTPClient, the code is as follows:

 HttpClient                                             lhc_client

 Integer                                                  li_ret , i , li_StatusCode

 String                                                    ls_url , ls_data, ls_body , ls_ret


 ls_url ="http://localhost/invoice/n_webservice.asmx"                                   

 ls_body = '<?xml version="1.0" encoding="utf-8"?>'+&

 '<soap:Envelope xmlns:xsi="" '+&

 'xmlns:xsd="" xmlns:soap="">'+&

 '  <soap:Body>'+&

 '    <of_add xmlns="">'+&

 '      <ai_test>2</ai_test>'+&

 '    </of_add>'+&

 '  </soap:Body>'+&



 lhc_client = CREATE httpClient

 lhc_client.SetRequestHeader("Content-Type", "text/xml")


 li_StatusCode = lhc_client.GetResponseStatusCode()

 ls_ret = lhc_client.GetResponseStatusText( )

 li_ret = lhc_client.getresponsebody(ls_data)

 DESTROY lhc_client

If you use the PBDOM object to build the XML content, here's what it looks like:

 HttpClient                                          lhc_client

 PBDOM_Builder                               lpbdom_Builder

 PBDOM_Document                          lpbdom_doc

 PBDOM_ProcessingInstruction        lpbdom_process

 PBDOM_ELEMENT                          lpbdom_root, lpbdom_body, lpbdom_method, lpbdom_arg

 Integer                                                li_ret , i , li_StatusCode

 String                                                   ls_url, ls_data, ls_value, ls_body, ls_ret, ls_rootname


 ls_url ="http://localhost/invoice/n_webservice.asmx"                   

 ls_rootname ="Envelope"                                                                          


                lpbdom_doc = CREATE PBDOM_Document


                lpbdom_process = CREATE PBDOM_ProcessingInstruction


                lpbdom_process.setvalue("version", "1.0")

                lpbdom_process.setvalue("encoding", "utf-8")                                                                                                                     


                DESTROY lpbdom_process


                lpbdom_root = lpbdom_doc.getrootelement()








                lpbdom_body = CREATE PBDOM_Element

                lpbdom_body.setname( "Body")

                lpbdom_body.setnamespace( "soap", "", False)


                lpbdom_method = CREATE PBDOM_Element

                lpbdom_method.setname( "of_add")

                lpbdom_method.addnamespacedeclaration( "", "")


                lpbdom_arg = CREATE PBDOM_Element

                lpbdom_arg.setname( "ai_test")

                lpbdom_arg.settext( "2")


                lpbdom_method.addcontent( lpbdom_arg)

                lpbdom_body.addcontent( lpbdom_method)

                lpbdom_root.addcontent( lpbdom_body)

                ls_body  = lpbdom_doc.savedocumentintostring( )                           //get new xml

 CATCH ( PBDOM_Exception pbde )  

                MessageBox( "PBDOM Exception", pbde.getMessage() )

 CATCH ( PBXRuntimeError re )  

                MessageBox( "PBNI Exception", re.getMessage() )


 IF isvalid(lpbdom_arg)                   THEN     DESTROY lpbdom_arg

 IF isvalid(lpbdom_method)            THEN     DESTROY lpbdom_method

 IF isvalid(lpbdom_body)                THEN     DESTROY lpbdom_body

 IF isvalid(lpbdom_doc)                  THEN     DESTROY lpbdom_doc


 lhc_client = CREATE httpClient

 lhc_client.SetRequestHeader("Content-Type", "text/xml")


 li_StatusCode = lhc_client.GetResponseStatusCode()

 ls_ret = lhc_client.GetResponseStatusText( )

 li_ret = lhc_client.getresponsebody(  ls_data)

 DESTROY lhc_client

3. Use the PBDOM Object to Get the Specified Content in the XML String.

 The content of the XML string to be obtained:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="" xmlns:xsd="" xmlns:soap="">
    <of_addResponse xmlns="">

Execute the following PB code can get the value of the of_addResult element in the returned XML string from the Soap Web Service.

 lpbdom_Builder = CREATE PBDOM_BUILDER


                // generate XML Document

                lpbdom_Doc = lpbdom_Builder.BuildFromString( ls_data )           

                ls_value = lpbdom_Doc.GetRootElement().&

                GetChildElement("Body", "soap","").&



 CATCH (PBDOM_Exception lpbdom_Except)

                // Error Handling goes here,

                MessageBox( "PBDOM_Exception", lpbdom_Except.GetExceptionCode())


 DESTROY lpbdom_Builder