I am new to xml writing and parsing in Delphi.
I have a string called szServerResponse returned by an XML request. I have written this string to a file shown in Fig 1,
so it's easier to read.
Fig 1.
<?xml version="1.0"?>
<response>
<result>1</result>
<result-text>Step 1 completed</result-text>
<transaction-id>3679631607</transaction-id>
<result-code>100</result-code>
<form-url>
https://secure.apspaymentgateway.com/api/v2/three-step/532q2f02</form-url>
</response>
Fig 2 shows the code I have to parse the xml document
var XMLResponse : IXMLDOCUMENT;
xmlStatusInfo, xmlresult : IXMLNODE;
szServerResponse: string;
begin
.......
XMLResponse := LoadXMLData(szServerResponse);
xmlStatusInfo := XMLResponse.DocumentElement.ChildNodes['response']; // (*)
szFormUrl := xmlstatusInfo.ChildNodes['form-url'].Text;
szStatusDescription := xmlstatusInfo.ChildNodes['result-text'].Text;
But both szFormUrl and szStatusDescription are blank if I inspect them. I suspect that line (*) is the culprit so I have replaced it by
a) xmlStatusInfo := XMLResponse.DocumentElement.ChildNodes[0]; // this also gives me blank szFormUrl and szStatusDescription
b) xmlResult := XMLResponse.ChildNodes.FindNode('result');
ShowMessage(xmlResult.Text);
b) crashes on the showMessage because xmlResult is nil
Any idea what I am missing?
Thanks
Cornelia
Connect with Us