Count the number of nodes in a xml lazarus / 21-General ---------------------------------------------------------------------- folkeu08 · 2024-01-01 10:10 Hi the Team, I am creating an xml file from a geocoding application. When reading the xml, I would like to know the number of polygons present by counting the number of "" nodes present (5 in our test.xml file). I started with the "Show node names" example from the page https://wiki.lazarus.freepascal.org/XML_Tutorial/fr but I get errors if I use my file. I guess it doesn't work with my file because I still have other nodes under "Placemark". Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var   Document: TXMLDocument;   i, j, K: Integer;  begin    ReadXMLFile(Document, 'test.kml');    Memo.Lines.Clear;    with Document.DocumentElement.ChildNodes do    //with Document.DocumentElement.ChildNodes.Item[1] do      begin        k := 0;        for i := 0 to (Count - 1) do          begin            Memo.Lines.Add(Item[i].NodeName + ' ' + Item[i].Attributes.Item[0].NodeValue);            for j := 0 to (Item[i].ChildNodes.Count - 1) do              begin                Memo.Lines.Add(Item[i].ChildNodes.Item[j].NodeName + ' ' + Item[i].ChildNodes.Item[j].FirstChild.NodeValue);                K := K+1;              end;          end;      end;   Showmessage(IntToStr(K));   Document.Free; end;                                 The second step will be to insert the longitude and latitude values ​​for each polygon of each node into a SQLite table (or 2 if necessary). The goal is to draw these polygons using "lazmapviewer" without having to reread the relevant XML. Thanks for your help as I'm lost with the terminology "Node" and "ChildNode". English is not my native language. Francois You must renam the file test.txt in test.kml (Thanks) ---------------------------------------------------------------------- paweld · 2024-01-02 05:43 Hi,  Here you have an example application that reads kml files and allows you to draw each polygon (placemark): https://forum.lazarus.freepascal .org/index.php/topic,64628.msg491620.html#msg491620 ---------------------------------------------------------------------- folkeu08 · 2024-01-02 15:06 Good morning, Exactly, I'm trying to cheat by counting the number of items in your source's listBox but I can't get anything right. I'm a complete beginner and have never used pointers. I don't understand what the code does with Stax and so I'm going there haphazardly. Francois ---------------------------------------------------------------------- paweld · 2024-01-02 18:27 SAX is a different way of reading XML files. It doesn't treat the xml as a tree of objects, but reads it like a text file telling you which node it is in. This is the most convenient way for me to read xml files in most cases. Wanting to read the values, you have to indicate in the SAXStartElement and SAXEndElement routines from which location they are to be retrieved - that's what I use the access path for (attached is the application with which I retrieve them). I also add to the attachment a modified application for reading KML files - I added information about placemark count and coordinate points count If you have any questions, ask - I'll answer to the best of my ability