Problem reading xmlnode

giangia76
Member Posts: 1
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.

Where I am wrong?
Thanks
Gianluca
<?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.

Where I am wrong?
Thanks
Gianluca
0
Answers
-
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions