Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: XMLparsing


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 2 - Last Post: Jun 29, 2017 9:59 AM Last Post By: Cornelia von Sc...
Cornelia von Sc...

Posts: 7
Registered: 11/4/16
XMLparsing  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 28, 2017 5:50 PM
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
Antonio Estevez

Posts: 665
Registered: 4/12/00
Re: XMLparsing  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 28, 2017 7:04 PM   in response to: Cornelia von Sc... in response to: Cornelia von Sc...
El 29/06/2017 a las 2:50, Cornelia von Schellwitz escribió:
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']; // (*)

XMLResponse.DocumentElement returns the root node (<response> in your example):

   xmlStatusInfo := XMLResponse.DocumentElement;
Cornelia von Sc...

Posts: 7
Registered: 11/4/16
Re: XMLparsing  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 29, 2017 9:59 AM   in response to: Antonio Estevez in response to: Antonio Estevez
Antonio Estevez wrote:
El 29/06/2017 a las 2:50, Cornelia von Schellwitz escribió:
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']; // (*)

XMLResponse.DocumentElement returns the root node (<response> in your example):

   xmlStatusInfo := XMLResponse.DocumentElement;

Thanks so much , this worked!

Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02