Within this XML file i need to store the first 3 elements within a temp table. After selecting the node path how can I essentially skip onto the next node? Or only select the 3 from the header to apply to the body.
In this instance I have I want to store the 'Location, Component and Comment' within the thead.
xmlNodeListDataHeader := xmlDoc.SelectNodes('hr/table/thead/tr/th');
So when looping through the tbody I only want to store the lines highlighted and skip the rest. How can this be done?
xmlNodeListDataHeader := xmlDoc.SelectNodes('hr/table/thead/tr/th');
xmlNodeListData := xmlDoc.SelectNodes('hr/table/tbody/tr/td');
FOR intNodeHeader := 0 TO xmlNodeListDataHeader.Count-1 DO BEGIN
xmlNodeHeader := xmlNodeListDataHeader.Item(intNodeHeader)
END;
FOR intNode := 0 TO xmlNodeListData.Count-1 DO BEGIN
xmlNode := xmlNodeListData.Item(intNode);
MESSAGE('%1', xmlNode.InnerText);
// Store the items in a temp table
END;
Answers
So you need to convert is with xslt scheme or count your way through it, but that is dangerous if order change.
xmlDoc := xmlDoc.XmlDocument();
xmlDoc.Load('\\tioga-eng\Shared\NavData_Public\Testing\' + cuCPUtils.UserBatch() + 'BOT2.xml');
IF FindNode(xmlDoc, '//table/tbody', XMLNode) THEN BEGIN
// Get all <tr> nodes
XMLNodeList := XMLNode.SelectNodes('tr');
Nodes := XMLNodeList.Count;
FOR intNode := 0 TO Nodes -1 DO BEGIN
XMLNode2 := XMLNodeList.ItemOf(intNode);
// All <td> nodes inside the <tr> node
XMLNodeList2 := XMLNode2.SelectNodes('td');
Nodes2 := XMLNodeList2.Count;
FOR intNode2 := 0 TO Nodes2 -1 DO BEGIN
XMLNode3 := XMLNodeList2.ItemOf(intNode2);
IF intNode2 IN [0,1,2] THEN BEGIN
IF NOT ISNULL(XMLNode3) THEN
Values[intNode2+1] := XMLNode3.InnerText
ELSE
Values[intNode2+1] := '';
END;
END;
END;
END;