OnRun() GetTable; GetTable() XMLDoc := XMLDoc.XmlDocument; // Assuming your XML file is here XMLDoc.Load('c:\temp\table.xml'); // Go to the <tbody> part of the file IF FindNode(XMLDoc, '//table/tbody', XMLNode) THEN BEGIN // Get all <tr> nodes XMLNodeList := XMLNode.SelectNodes('tr'); Nodes := XMLNodeList.Count; FOR i := 0 TO Nodes-1 DO BEGIN XMLNode2 := XMLNodeList.ItemOf(i); // All <td> nodes inside the <tr> node XMLNodeList2 := XMLNode2.SelectNodes('td'); Nodes2 := XMLNodeList2.Count; FOR j := 0 TO Nodes2-1 DO BEGIN XMLNode3 := XMLNodeList2.ItemOf(j); IF j IN [0,1,2] THEN BEGIN IF NOT ISNULL(XMLNode3) THEN Values[j+1] := XMLNode3.InnerText ELSE Values[j+1] := ''; END; END; MESSAGE('%1 /%2 %3', Values[1], Values[2], Values[3]); END; END; FindNode(XMLRootNode : DotNet "System.Xml.XmlNode";NodePath : Text[250];VAR FoundXMLNode : DotNet "System.Xml.XmlNode") : Boolean FoundXMLNode := XMLRootNode.SelectSingleNode(NodePath); IF ISNULL(FoundXMLNode) THEN EXIT(FALSE) ELSE EXIT(TRUE);
OBJECT Codeunit 50018 Read Table XHTML { OBJECT-PROPERTIES { Date=28/07/17; Time=18:18:54; Modified=Yes; Version List=WS; } PROPERTIES { OnRun=BEGIN GetTable; END; } CODE { PROCEDURE GetTable@1000000005(); VAR XMLDoc@1000000005 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlDocument"; XMLNode@1000000004 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlNode"; XMLNode2@1000000006 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlNode"; XMLNode3@1000000009 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlNode"; XMLNodeList@1000000003 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlNodeList"; XMLNodeList2@1000000002 : DotNet "'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlNodeList"; i@1000000001 : Integer; j@1000000008 : Integer; Nodes@1000000000 : Integer; Nodes2@1000000007 : Integer; Values@1000000010 : ARRAY [3] OF Text; BEGIN XMLDoc := XMLDoc.XmlDocument; // Assuming your XML file is here XMLDoc.Load('c:\temp\table.xml'); // Go to the <tbody> part of the file IF FindNode(XMLDoc, '//table/tbody', XMLNode) THEN BEGIN // Get all <tr> nodes XMLNodeList := XMLNode.SelectNodes('tr'); Nodes := XMLNodeList.Count; FOR i := 0 TO Nodes-1 DO BEGIN XMLNode2 := XMLNodeList.ItemOf(i); // All <td> nodes inside the <tr> node XMLNodeList2 := XMLNode2.SelectNodes('td'); Nodes2 := XMLNodeList2.Count; FOR j := 0 TO Nodes2-1 DO BEGIN XMLNode3 := XMLNodeList2.ItemOf(j); IF j IN [0,1,2] THEN BEGIN IF NOT ISNULL(XMLNode3) THEN Values[j+1] := XMLNode3.InnerText ELSE Values[j+1] := ''; END; END; MESSAGE('%1 /%2 %3', Values[1], Values[2], Values[3]); END; END; END; PROCEDURE FindNode@3(XMLRootNode@1000 : DotNet "'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlNode";NodePath@1001 : Text[250];VAR FoundXMLNode@1002 : DotNet "'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlNode") : Boolean; BEGIN FoundXMLNode := XMLRootNode.SelectSingleNode(NodePath); IF ISNULL(FoundXMLNode) THEN EXIT(FALSE) ELSE EXIT(TRUE); END; BEGIN END. } }
Answers
And not Automations, but DOTNET.
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/
Hi, thank you for this. If i wanted to take this response an edit the document and then save the file, roughly how would I do that?
Looks like this URL ('http://boi.org.il/currency.xml') doesn't work, so I changed to other that works, and here is the code:
And here you can see the variables used.
In the procedure GetResponse, you can change the way the file is managed and instead of load a XMLDocument with it , first try to clean up a little.
If you can post the complete file I can take a look and see how to do it.
Regads.
My document looks like this now simplified. I've done select node as such
xmlNodeListDataHeader := xmlDoc.SelectNodes('hr/table/thead/tr/tr'); as well as xmlNodeListData := xmlDoc.SelectNodes('hr/table/tbody/tr/td');
Now what I need to do is get for each 'Location,Component, Comment'
or 'C4,PN-0000170,1NF 0402 50V C0G 5%' in each node. I understand how I can use something like txt = xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue;
but how in the below example could I apply this?
<?xml version="1.0" encoding="UTF-8"?>
<hr>
<table>
<thead class="DataTable">
<tr class="DataTable">
<th class="DataTable">Line</th>
<th class="DataTable">Location</th>
<th class="DataTable">Component</th>
<th class="DataTable">Comment</th>
<th class="DataTable">Stock Location</th>
<th class="DataTable">X</th>
<th class="DataTable">Y</th>
<th class="DataTable">Z</th>
<th class="DataTable">Angle</th>
<th class="DataTable">Group</th>
<th class="DataTable">Notes</th>
</tr>
</thead>
<tbody>
<tr class="DataTable">
<th class="DataTable">1</th>
<td class="DataTable">C4</td>
<td class="DataTable">PN-0000170</td>
<td class="DataTable">1NF 0402 50V C0G 5%</td>
<td class="DataTable">0</td>
<td class="DataTableNumeric">81.318mm</td>
<td class="DataTableNumeric">47.984mm</td>
<td class="DataTableNumeric">0.000mm</td>
<td class="DataTableNumeric">-90</td>
<td class="DataTable">0</td>
</tr>
<tr class="DataTable">
<th class="DataTable">2</th>
<td class="DataTable">C9</td>
<td class="DataTable">PN-1007815</td>
<td class="DataTable">10PF 0402 50V C0G 1%</td>
<td class="DataTable">0</td>
<td class="DataTableNumeric">86.116mm</td>
<td class="DataTableNumeric">47.489mm</td>
<td class="DataTableNumeric">0.000mm</td>
<td class="DataTableNumeric">180</td>
<td class="DataTable">0</td>
</tr>
</table>
</hr>
You already have a post for this issue.
In the file you post is missing a </tbody> between the last <tr> and </table>
With this code you can get the values you want
And here you can get all variables
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!