Question:
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="http://schemas.xmlsoap.org/soap/envelope/" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:vwa="http://xmldefs.example.com/Technical/Addressing/V1"> <soapenv:Header> <wsa:MessageID>urn</wsa:MessageID> <wsa:To>ws://example.com/Wholesale/TelematicEventNotificationService/V1</wsa:To> <wsa:Action>http://xmldefs.example.com/Wholesale/TelematicEventNotificationService/V1/TelematicEventNotificationServicePortType/SyncTelematicEvent</wsa:Action> <vwa:Country wsa:isReferenceParameter="true">CN</vwa:Country> <vwa:Brand wsa:IsReferenceParameter="true">V</vwa:Brand> <vwa:Stage wsa:IsReferenceParameter="true">QualityAssurance</vwa:Stage> </soapenv:Header> <soapenv:Body> <GetQuote xmlns="http://www.webserviceX.NET/"> <A1>MSFT</A1> <B1> <B2 xmlns="http://www.webserviceX.net/” > <B3>SSS</B3> </B2> </B1> <C1> <C2> <C3>VVV</C3> </C2> </C1> </GetQuote> </soapenv:Body> </soapenv:Envelope>
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> .... </soapenv:Envelope>';
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...