Error when parsing XML lazarus / 31-LCL ---------------------------------------------------------------------- ElRon21 · 2017-12-28 10:06 Hi everybody, I'm new to programming with freepascal/lazarus. I want to read nodes from an XML-File, but i get an Errormessage each time. Here is an excerpt of the xml: 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                       Smartkamera Leuze                konfiguriert                10.62.121.120              10.62.121.138                              Smartkamera Leuze                unkonfiguriert                192.168.60.101                192.168.60.138                              Kamera Kognex              default                default                192.168.1.1                              Regler                Lenze                default                172.18.100.88  And here is the excerpt of my code which i use to read the file: 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 procedure TForm1.btTestClick(Sender: TObject);begin   datei := 'device.xml';   knoten := 'Group';   ReadXML(datei, knoten);end;   procedure TForm1.ReadXML(var datei, knoten: string);var  Doc: TXMLDocument;  PassNode: TDOMNode;  NodeText: String;  begin  cbDevice.Items.Append(PATH+datei);  cbDevice.Items.Append(knoten);    try    { Read in xml file from disk }    ReadXMLFile(Doc, PATH+datei);     PassNode :=Doc.DocumentElement.FindNode(knoten);    try      NodeText :=PassNode.FirstChild.NodeValue;    finally      PassNode.Free;    end;    cbDevice.Items.Append(NodeText);  finally  Doc.Free;  end; end;  Now when I start the program i get an error (attached) each time i press the "Test"-button. Can anybody give me an hint what I'm doing wrong? ---------------------------------------------------------------------- wp · 2017-12-28 10:15 Probably this: You must not free the PassNode. PassNode is part of the XMLDocument, it was created when reading the XML file. So: you did not create it --> you don't destroy it. It will be destroyed by the XMLDocument. 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 procedure TForm1.ReadXML(var datei, knoten: string);var  Doc: TXMLDocument = nil;  PassNode: TDOMNode;  NodeText: String;begin  cbDevice.Items.Append(PATH+datei);  cbDevice.Items.Append(knoten);    try    { Read in xml file from disk }    ReadXMLFile(Doc, PATH+datei);     PassNode :=Doc.DocumentElement.FindNode(knoten);    if PassNode = nil then  // take care of node not being found      NodeText := '[not found]'    else      NodeText :=PassNode.FirstChild.NodeValue;    cbDevice.Items.Append(NodeText);  finally    Doc.Free;  end;end; ---------------------------------------------------------------------- ElRon21 · 2017-12-28 10:24 Thank's for you fast answer. It helped me a lot. My node was not found. Now I'll have to check why... ---------------------------------------------------------------------- wp · 2017-12-28 11:22 XMLDocument.FindNode searches only in the top-level nodes. I don't know if there is a ready-to-use function, but you can use this recursive function to look deeper: 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 program project1; {$mode objfpc}{$H+} uses  Classes, laz2_dom, laz2_xmlread;   function FindNode(AParent: TDOMNode; AName: String): TDOMNode;  var  node: TDOMNode;  begin    Result := AParent.FindNode(AName);    if Result = nil then begin      node := AParent.FirstChild;      while node <> nil do begin        Result := FindNode(node, AName);        if Result <> nil then          exit;        node := node.NextSibling;    end;    end;  end; var  doc: TXMLDocument = nil;  node: TDOMNode; const  NodeName = 'KeyMapping';begin  try    ReadXMLFile(Doc, 'editoroptions.xml');    node := FindNode(Doc.FirstChild, NodeName);    if node = nil then      WriteLn('Node "' + NodeName + '" not found.')    else      WriteLn('Node "' + NodeName + '" found.');  finally    Doc.Free;  end;   ReadLn;end.