Problem reading xmlnode

From webserwis I get the following file XML.

<?xml version="1.0" encoding="UTF-8"?>
<reservations>
<reservation>
<comId>84913135</comId>
<resId>63960910</resId>
<lanId>11</lanId>
<voucher>REZ/2022/0153</voucher>
<term>
<from>2022-11-20 14:00:00</from>
<to>2022-11-23 10:00:00</to>
</term>
</reservation>
<reservation>
<comId>85098208</comId>
<resId>64100584</resId>
<lanId>11</lanId>
<voucher>REZ/2022/0154</voucher>
<term>
<from>2022-11-26 14:00:00</from>
<to>2022-12-01 10:00:00</to>
</term>
</reservation>
<reservation>
<comId>84571216</comId>
<resId>63713095</resId>
<lanId>11</lanId>
<voucher>REZ/2022/0152</voucher>
<term>
<from>2022-12-07 14:00:00</from>
<to>2022-12-10 10:00:00</to>
</term>
</reservation>on>
</reservations>

I read the ‘reservation’ nodes with the following:

if ResponseXmlDoc.SelectNodes('//reservation', NodeList) then begin

FOR i := 1 TO NodeList.Count DO begin
NodeList.Get(i, ChildNode);
XmlElement := ChildNode.AsXmlElement();
CASE XmlElement.Name OF
'reservation':
begin
ElaborateReservation(ChildNode);
end;
end;
end;
end


After then i search some information in the node:

local procedure ElaborateReservation(var ChildNodeRes: XmlNode)
var
XMLElement: XmlElement;
ChildNodeStatus: XmlNode;
ChildNodeStatus2: XmlNode;
Begin
Message(Format(ChildNodeRes));

if ChildNodeRes.SelectSingleNode('//comId', ChildNodeStatus) then begin
XmlElement := ChildNodeStatus.AsXmlElement();
HotelReservation.ID := XmlElement.InnerText;
Message(HotelReservation.ID);
end;
if ChildNodeRes.SelectSingleNode('//voucher', ChildNodeStatus) then begin
XmlElement := ChildNodeStatus.AsXmlElement();
HotelReservation."Voucher No." := XmlElement.InnerText;
end;
if ChildNodeRes.SelectSingleNode('//term', ChildNodeStatus) then begin
if ChildNodeStatus.SelectSingleNode('//from', ChildNodeStatus2) then begin
XmlElement := ChildNodeStatus2.AsXmlElement();
HotelReservation."Date From" := ConvertToDateTime(XmlElement.InnerText);
end;

if ChildNodeStatus.SelectSingleNode('//to', ChildNodeStatus2) then begin
XmlElement := ChildNodeStatus2.AsXmlElement();
HotelReservation."Date To" := ConvertToDateTime(XmlElement.InnerText);
end;
end;
end;


The problem is that I receive alwais the data of the first node but in the message I see that I read next node.

f9uxmakdx04a.jpg


Where I am wrong?

Thanks
Gianluca












Answers

Sign In or Register to comment.