Archived Forum Post

Index of archived forum posts


How to Generate SOAP XML for HTTP Request?

Feb 21 '14 at 09:18

How can the Chilkat XML API be used to generate SOAP in Delphi like below? This is to be used as the XML body of an HTTP request.

<?xml version="1.0" encoding="UTF-8" ?>
<soapenv:Envelope xmlns:soapenv=""
        <vwa:Country wsa:isReferenceParameter="true">CN</vwa:Country>
        <vwa:Brand wsa:IsReferenceParameter="true">V</vwa:Brand>
        <vwa:Stage wsa:IsReferenceParameter="true">QualityAssurance</vwa:Stage>
        <GetQuote xmlns="http://www.webserviceX.NET/">
                <B2 xmlns="” >


My recommendation is that there is no need to use an XML API (Chilkat or otherwise) to generate XML that is structurally the same in every case, except for the various pieces that compose the actual content. An XML API is good for parsing existing XML to extract information, or for modifying existing XML, but to create XML that is nothing more than boilerplate + plugged-in values, using an XML API is over-complicating matters.

What I would recommend is to simply insert the pre-composed and "templated" SOAP XML string directly within your source code. For example:

soapXmlStr := '<?xml version="1.0" encoding="UTF-8" ?> .... 
    <A1>STOCK_SYMBOL</A1> .... 

Then simply write code that does string replacements for the various parts: Replace "STOCK_SYMBOL" with the actual value, etc. You then have the SOAP XML that can be passed to the Chilkat HTTP method.

There is no need to use an XML API to build an XML string that can just as well be built with simple string pattern replacement, or alternatively, simple string concatenation.


I agree your solution. However, I don't want to save XML to file and load it again to Chilkat HTTP method.

Is there any possible to use Chilkat XML component to assign the value of the specific nodes?

I found "IChilkatXml.FindChild()" method can do find the specific node, but how can I assign the value to node?

For example: soapReq := TChilkatXml.Create(Self).ControlInterface; soapReq.LoadXmlFile(programpath+XML_temp); soapReq.FindChild('A1').Content:='32434';<----------------------Here returns error. soapReq.GetRoot2();


There is no file in the solution I proposed. The XML template is nothing more than a literal string in your Delphi source code. It is NOT loaded from a file.


I do follow your suggestion, but I found it quite hard to make sure the value of the each XML nodes should not exist anywhere else in the XML or any other phrase has part of it. Especially for some XML has thousands nodes...