Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   XML FIndNode Frage (https://www.delphipraxis.net/211878-xml-findnode-frage.html)

TurboMagic 15. Nov 2022 21:28

XML FIndNode Frage
 
Hallo,

gegeben sei D11.2 und eine Routine in der ich eine XML-Datei frisch erzeuge.

Delphi-Quellcode:
procedure TMyClass.SaveToXML(const FileName : string);
  LDocument: IXMLDocument;
  LOutput, LNodeElement: IXMLNode;
begin
  LDocument        := TXMLDocument.Create(nil);
  LDocument.Active := true;
  LDocument.Options := [doNodeAutoIndent];

  LDocument.DocumentElement := LDocument.CreateNode('DCCProject', ntElement, '');
  LOutput          := LDocument.DocumentElement.AddChild('OutputSettings', -1);
  LNodeElement     := LOutput.AddChild('ScriptOutputPath', -1);
  LNodeElement.Text := 'My text';

  LNodeElement := LDocument.ChildNodes.FindNode('OutputSettings');
  if Assigned(LNodeElement) then
    sleep(100);
Die Frage nun, warum er das zum testen eingebaute Sleep(100) nicht erreicht.
Liegt es daran, dass die XML-Datei zu dem Zeitpunkt noch nicht gespeichert wurde?

Kontext: ich spiele gerade mit Attributen rum und wie ich die evtl. nutzen könnte
um automatisch diverse Felder passend in die XML-Datei zu speichern. Dabei sollen
einige der Felder direkt unter <OutputSettings> landen und nicht jedes Mal einen neuen
<OutputSettings> Knoten erzeugen...
Bei manueller Ausgabe klappt das natürlich, bei der automatischen, wo beim ersten Mal
der <OutputSettings> Knoten erzeugt werden muss bisher nicht. Da erzeut er den für jedes zu speichernde Feld wieder... :(

Grüße
TurboMagic

himitsu 15. Nov 2022 21:34

AW: XML FIndNode Frage
 
vermutlich irgendwie so
Delphi-Quellcode:
LDocument.RootNode.FindNode('OutputSettings');
LDocument.DocumentElement.FindNode('OutputSettings');

// weil ;)
LDocument.ChildNodes.FindNode('DCCProject').ChildNodes.FindNode('OutputSettings');

TurboMagic 15. Nov 2022 22:23

AW: XML FIndNode Frage
 
Danke! Die letzte Codezeile funktioniert!


Alle Zeitangaben in WEZ +1. Es ist jetzt 09:22 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz