Results 1 to 11 of 11

Thread: TXMLDocument

  1. #1
    Win32.Trojan.Heur.Herby
    Join Date
    Dec 2003
    Location
    Nuenen of all places
    Posts
    105

    TXMLDocument

    Hoi

    Ben al dagen aan het stoeien met TXMLDocument, is de eerste keer dat ik het toe pas en wordt en langzamerhand geflipt van.
    Wat ik ook doe, welke voorbeeld ik ook pak, ik krijg het niet fatsoenlijk werkend.

    <RANT>
    Uiteindelijke bedoeling is dat ik hiermee een PersonalPOI database kan aanmaken voor Skoda/Seat/Volkswagen sinds die lui besloten hebben de site die dit maakte uit de lucht te halen.
    Blijkbaar is mijn bijna 2000 euro kostende navigatie in een auto van 11-2015 obsolete geworden want dit werd door hen zo aangegeven.
    </RANT>
    anyways.... :-)

    Met de volgende procedure maak ik succesvol de XML aan.
    Code:
    procedure TFormMain.FileWriteXML;
    var
      RootNode              : IXMLNode;
      ConfigNode            : IXMLNode;
      CategoriesNode        : IXMLNode;
      CategoryNode          : IXMLNode;
      I                     : integer;
    
    begin
      FXMLDoc                                             := TXMLDocument.Create(nil);                // Create XML Document
      try
        FXMLDoc.Active                                    := true;
        FXMLDoc.FileName                                  := FXMLFileName;
        FXMLDoc.Version                                   := '1.0';
        FXMLDoc.StandAlone                                := 'yes';
        FXMLDoc.Options                                   := FXMLDoc.Options + [doNodeAutoIndent];
    
        FXMLDoc.DocumentElement                           := FXMLDoc.CreateNode('XMLConfig', ntElement, '');
        FXMLDoc.DocumentElement.Attributes['Application'] := ApplicationName;
        ConfigNode                                        := FXMLDoc.DocumentElement.AddChild('Config');
    
        If FWorkingFolderIcons    = '' then
          FWorkingFolderIcons                             := 'Icons';
    
        If FWorkingFolderInput    = '' then
          FWorkingFolderInput                             := 'Input';
    
        If FWorkingFolderOutput   = '' then
          FWorkingFolderOutput                            := 'Output';
    
        If FWorkingFolderTemp     = '' then
          FWorkingFolderTemp                              := 'Temp';
    
        If FWorkingFolderTemplate = '' then
          FWorkingFolderTemplate                          := 'Template';
    
        ConfigNode.Attributes ['InputFolder']             := FWorkingFolderInput;
        ConfigNode.Attributes ['OutputFolder']            := FWorkingFolderOutput;
        ConfigNode.Attributes ['TempFolder']              := FWorkingFolderTemp;
        ConfigNode.Attributes ['TempplateFolder']         := FWorkingFolderInput;
    
        CategoriesNode                                    := FXMLDoc.DocumentElement.AddChild('Categories');
        CategoriesNode.Attributes ['IconFolder']          := 'Icons';
    
        for I := 0 to CategoryListView.Items.Count do
          begin
            CategoryNode                                  := CategoriesNode.AddChild('Category');
            CategoryNode.Attributes ['Name']              := CategoryListView.Items[I].Caption;
            CategoryNode.Attributes ['Icon']              := CategoryListView.Items[I].SubItems[0];
            CategoryNode.Attributes ['WarningSound']      := CategoryListView.Items[I].SubItems[1];
            CategoryNode.Attributes ['WarningDistance']   := CategoryListView.Items[I].SubItems[2];
          end;
    
        FXMLDoc.SaveToFile(FXMLFileName);
      finally
        FXMLDoc.Active      := false;
        FXMLDoc := nil;
      end;
    end;
    Bovenstaand maakt bv de volgende XML aan.

    Code:
    <?xml version="1.0" standalone="yes"?>
    <XMLConfig Application="POItool">
      <Config TempFolder="Temp" TemplateFolder="Template" InputFolder="Input" OutputFolder="Output"/>
      <Categories IconFolder="Icons">
        <Category Name="Speedcam Fixed" Icon="speedcam.png" WarningSound="Yes" WarningDistance="150000"/>
      </Categories>
    </XMLConfig>
    
    Waar ik niet uit kom is hoe dat ik het geheel weer juist terug lees.
    Met de Config sectie wil ik uiteindelijk de variables weer zetten met de locaties.
    Met de Categories sectie wil ik uiteindelijk de variable weer zetten met de locatie van de ICON folder en de bijhorende category regels (nu 1) weer in te lezen inde listview.

    Is er iemand die me hiermee de juiste weg op kan helpen want uiteindelijk heb ik nog steeds niks, als ik denk weer iets te hebben kom ik weer in een AV uit.

    Alvast bedankt.

    Gr
    Herby

    P.S.
    Geen idee of de code voor het maken van de XML wel een beetje klopt.

  2. #2
    Het zou een optie kunnen zijn om de xml databinder te gebruiken. (Als je even googled op xml databinder delphi, kom je redelijk wat voorbeelden tegen). Wat de databinder doet, is je xml of de definitie daarvan omzetten in een klasse. Hierdoor wordt het allemaal wat makkelijker. Zo ziet de XML data bind er uit van jou XML (heb alleen meerdere category items toegevoegd zodat de bind wizard weet dat het om meerdere items gaat).

    Jou aangepaste XML:
    Code:
    <?xml version="1.0" standalone="yes"?>
    <XMLConfig Application="POItool">
      <Config TempFolder="Temp" TemplateFolder="Template" InputFolder="Input" OutputFolder="Output"/>
      <Categories IconFolder="Icons">
        <Category Name="Speedcam Fixed" Icon="speedcam.png" WarningSound="Yes" WarningDistance="150000"/>
        <Category Name="Speedcam Fixed" Icon="speedcam.png" WarningSound="Yes" WarningDistance="150000"/>
      </Categories>
    </XMLConfig>
    De door delphi gemaakte XML databind unit:

    Code:
    {***********************************************}
    {                                               }
    {               XML Data Binding                }
    {                                               }
    {         Generated on: 29-7-2018 14:03:30      }
    {       Generated from: E:\Documenten\nld.xml   }
    {   Settings stored in: E:\Documenten\nld.xdb   }
    {                                               }
    {***********************************************}
    
    unit nld;
    
    interface
    
    uses Xml.xmldom, Xml.XMLDoc, Xml.XMLIntf;
    
    type
    
    { Forward Decls }
    
      IXMLXMLConfigType = interface;
      IXMLConfigType = interface;
      IXMLCategoriesType = interface;
      IXMLCategoryType = interface;
    
    { IXMLXMLConfigType }
    
      IXMLXMLConfigType = interface(IXMLNode)
        ['{BA392240-6E2B-4744-A214-13DF39E9D583}']
        { Property Accessors }
        function Get_Application: UnicodeString;
        function Get_Config: IXMLConfigType;
        function Get_Categories: IXMLCategoriesType;
        procedure Set_Application(Value: UnicodeString);
        { Methods & Properties }
        property Application: UnicodeString read Get_Application write Set_Application;
        property Config: IXMLConfigType read Get_Config;
        property Categories: IXMLCategoriesType read Get_Categories;
      end;
    
    { IXMLConfigType }
    
      IXMLConfigType = interface(IXMLNode)
        ['{E5A90EC3-428E-4632-A8BD-6BBB15687EB2}']
        { Property Accessors }
        function Get_TempFolder: UnicodeString;
        function Get_TemplateFolder: UnicodeString;
        function Get_InputFolder: UnicodeString;
        function Get_OutputFolder: UnicodeString;
        procedure Set_TempFolder(Value: UnicodeString);
        procedure Set_TemplateFolder(Value: UnicodeString);
        procedure Set_InputFolder(Value: UnicodeString);
        procedure Set_OutputFolder(Value: UnicodeString);
        { Methods & Properties }
        property TempFolder: UnicodeString read Get_TempFolder write Set_TempFolder;
        property TemplateFolder: UnicodeString read Get_TemplateFolder write Set_TemplateFolder;
        property InputFolder: UnicodeString read Get_InputFolder write Set_InputFolder;
        property OutputFolder: UnicodeString read Get_OutputFolder write Set_OutputFolder;
      end;
    
    { IXMLCategoriesType }
    
      IXMLCategoriesType = interface(IXMLNodeCollection)
        ['{CFD0DE3A-2A18-4C72-8630-EFC1953675B9}']
        { Property Accessors }
        function Get_IconFolder: UnicodeString;
        function Get_Category(Index: Integer): IXMLCategoryType;
        procedure Set_IconFolder(Value: UnicodeString);
        { Methods & Properties }
        function Add: IXMLCategoryType;
        function Insert(const Index: Integer): IXMLCategoryType;
        property IconFolder: UnicodeString read Get_IconFolder write Set_IconFolder;
        property Category[Index: Integer]: IXMLCategoryType read Get_Category; default;
      end;
    
    { IXMLCategoryType }
    
      IXMLCategoryType = interface(IXMLNode)
        ['{E3F37563-770C-44DA-ACE2-DFF6566F18FF}']
        { Property Accessors }
        function Get_Name: UnicodeString;
        function Get_Icon: UnicodeString;
        function Get_WarningSound: UnicodeString;
        function Get_WarningDistance: Integer;
        procedure Set_Name(Value: UnicodeString);
        procedure Set_Icon(Value: UnicodeString);
        procedure Set_WarningSound(Value: UnicodeString);
        procedure Set_WarningDistance(Value: Integer);
        { Methods & Properties }
        property Name: UnicodeString read Get_Name write Set_Name;
        property Icon: UnicodeString read Get_Icon write Set_Icon;
        property WarningSound: UnicodeString read Get_WarningSound write Set_WarningSound;
        property WarningDistance: Integer read Get_WarningDistance write Set_WarningDistance;
      end;
    
    { Forward Decls }
    
      TXMLXMLConfigType = class;
      TXMLConfigType = class;
      TXMLCategoriesType = class;
      TXMLCategoryType = class;
    
    { TXMLXMLConfigType }
    
      TXMLXMLConfigType = class(TXMLNode, IXMLXMLConfigType)
      protected
        { IXMLXMLConfigType }
        function Get_Application: UnicodeString;
        function Get_Config: IXMLConfigType;
        function Get_Categories: IXMLCategoriesType;
        procedure Set_Application(Value: UnicodeString);
      public
        procedure AfterConstruction; override;
      end;
    
    { TXMLConfigType }
    
      TXMLConfigType = class(TXMLNode, IXMLConfigType)
      protected
        { IXMLConfigType }
        function Get_TempFolder: UnicodeString;
        function Get_TemplateFolder: UnicodeString;
        function Get_InputFolder: UnicodeString;
        function Get_OutputFolder: UnicodeString;
        procedure Set_TempFolder(Value: UnicodeString);
        procedure Set_TemplateFolder(Value: UnicodeString);
        procedure Set_InputFolder(Value: UnicodeString);
        procedure Set_OutputFolder(Value: UnicodeString);
      end;
    
    { TXMLCategoriesType }
    
      TXMLCategoriesType = class(TXMLNodeCollection, IXMLCategoriesType)
      protected
        { IXMLCategoriesType }
        function Get_IconFolder: UnicodeString;
        function Get_Category(Index: Integer): IXMLCategoryType;
        procedure Set_IconFolder(Value: UnicodeString);
        function Add: IXMLCategoryType;
        function Insert(const Index: Integer): IXMLCategoryType;
      public
        procedure AfterConstruction; override;
      end;
    
    { TXMLCategoryType }
    
      TXMLCategoryType = class(TXMLNode, IXMLCategoryType)
      protected
        { IXMLCategoryType }
        function Get_Name: UnicodeString;
        function Get_Icon: UnicodeString;
        function Get_WarningSound: UnicodeString;
        function Get_WarningDistance: Integer;
        procedure Set_Name(Value: UnicodeString);
        procedure Set_Icon(Value: UnicodeString);
        procedure Set_WarningSound(Value: UnicodeString);
        procedure Set_WarningDistance(Value: Integer);
      end;
    
    { Global Functions }
    
    function GetXMLConfig(Doc: IXMLDocument): IXMLXMLConfigType;
    function LoadXMLConfig(const FileName: string): IXMLXMLConfigType;
    function NewXMLConfig: IXMLXMLConfigType;
    
    const
      TargetNamespace = '';
    
    implementation
    
    uses Xml.xmlutil;
    
    { Global Functions }
    
    function GetXMLConfig(Doc: IXMLDocument): IXMLXMLConfigType;
    begin
      Result := Doc.GetDocBinding('XMLConfig', TXMLXMLConfigType, TargetNamespace) as IXMLXMLConfigType;
    end;
    
    function LoadXMLConfig(const FileName: string): IXMLXMLConfigType;
    begin
      Result := LoadXMLDocument(FileName).GetDocBinding('XMLConfig', TXMLXMLConfigType, TargetNamespace) as IXMLXMLConfigType;
    end;
    
    function NewXMLConfig: IXMLXMLConfigType;
    begin
      Result := NewXMLDocument.GetDocBinding('XMLConfig', TXMLXMLConfigType, TargetNamespace) as IXMLXMLConfigType;
    end;
    
    { TXMLXMLConfigType }
    
    procedure TXMLXMLConfigType.AfterConstruction;
    begin
      RegisterChildNode('Config', TXMLConfigType);
      RegisterChildNode('Categories', TXMLCategoriesType);
      inherited;
    end;
    
    function TXMLXMLConfigType.Get_Application: UnicodeString;
    begin
      Result := AttributeNodes['Application'].Text;
    end;
    
    procedure TXMLXMLConfigType.Set_Application(Value: UnicodeString);
    begin
      SetAttribute('Application', Value);
    end;
    
    function TXMLXMLConfigType.Get_Config: IXMLConfigType;
    begin
      Result := ChildNodes['Config'] as IXMLConfigType;
    end;
    
    function TXMLXMLConfigType.Get_Categories: IXMLCategoriesType;
    begin
      Result := ChildNodes['Categories'] as IXMLCategoriesType;
    end;
    
    { TXMLConfigType }
    
    function TXMLConfigType.Get_TempFolder: UnicodeString;
    begin
      Result := AttributeNodes['TempFolder'].Text;
    end;
    
    procedure TXMLConfigType.Set_TempFolder(Value: UnicodeString);
    begin
      SetAttribute('TempFolder', Value);
    end;
    
    function TXMLConfigType.Get_TemplateFolder: UnicodeString;
    begin
      Result := AttributeNodes['TemplateFolder'].Text;
    end;
    
    procedure TXMLConfigType.Set_TemplateFolder(Value: UnicodeString);
    begin
      SetAttribute('TemplateFolder', Value);
    end;
    
    function TXMLConfigType.Get_InputFolder: UnicodeString;
    begin
      Result := AttributeNodes['InputFolder'].Text;
    end;
    
    procedure TXMLConfigType.Set_InputFolder(Value: UnicodeString);
    begin
      SetAttribute('InputFolder', Value);
    end;
    
    function TXMLConfigType.Get_OutputFolder: UnicodeString;
    begin
      Result := AttributeNodes['OutputFolder'].Text;
    end;
    
    procedure TXMLConfigType.Set_OutputFolder(Value: UnicodeString);
    begin
      SetAttribute('OutputFolder', Value);
    end;
    
    { TXMLCategoriesType }
    
    procedure TXMLCategoriesType.AfterConstruction;
    begin
      RegisterChildNode('Category', TXMLCategoryType);
      ItemTag := 'Category';
      ItemInterface := IXMLCategoryType;
      inherited;
    end;
    
    function TXMLCategoriesType.Get_IconFolder: UnicodeString;
    begin
      Result := AttributeNodes['IconFolder'].Text;
    end;
    
    procedure TXMLCategoriesType.Set_IconFolder(Value: UnicodeString);
    begin
      SetAttribute('IconFolder', Value);
    end;
    
    function TXMLCategoriesType.Get_Category(Index: Integer): IXMLCategoryType;
    begin
      Result := List[Index] as IXMLCategoryType;
    end;
    
    function TXMLCategoriesType.Add: IXMLCategoryType;
    begin
      Result := AddItem(-1) as IXMLCategoryType;
    end;
    
    function TXMLCategoriesType.Insert(const Index: Integer): IXMLCategoryType;
    begin
      Result := AddItem(Index) as IXMLCategoryType;
    end;
    
    { TXMLCategoryType }
    
    function TXMLCategoryType.Get_Name: UnicodeString;
    begin
      Result := AttributeNodes['Name'].Text;
    end;
    
    procedure TXMLCategoryType.Set_Name(Value: UnicodeString);
    begin
      SetAttribute('Name', Value);
    end;
    
    function TXMLCategoryType.Get_Icon: UnicodeString;
    begin
      Result := AttributeNodes['Icon'].Text;
    end;
    
    procedure TXMLCategoryType.Set_Icon(Value: UnicodeString);
    begin
      SetAttribute('Icon', Value);
    end;
    
    function TXMLCategoryType.Get_WarningSound: UnicodeString;
    begin
      Result := AttributeNodes['WarningSound'].Text;
    end;
    
    procedure TXMLCategoryType.Set_WarningSound(Value: UnicodeString);
    begin
      SetAttribute('WarningSound', Value);
    end;
    
    function TXMLCategoryType.Get_WarningDistance: Integer;
    begin
      Result := AttributeNodes['WarningDistance'].NodeValue;
    end;
    
    procedure TXMLCategoryType.Set_WarningDistance(Value: Integer);
    begin
      SetAttribute('WarningDistance', Value);
    end;
    
    end.
    En vervolgens hoe je het kunt gebruiken. ik heb niet alle properties gebruikt, maar daar kom je wel uit denk ik.
    Code:
    procedure TForm1.Button1Click(Sender: TObject);
    var
      XMLConfig: IXMLXMLConfigType;
      Config: IXMLConfigType;
      Categories: IXMLCategoriesType;
      Category: IXMLCategoryType;
      I: Integer;
    begin
      if OpenDialog1.Execute then
      begin
        XMLDocument1.LoadFromFile(OpenDialog1.FileName);
        XMLDocument1.Active := True;
    
        XMLConfig := GetXMLConfig(XMLDocument1);
    
        Config := XMLConfig.Config;
    
        Memo1.Lines.Add('Temp folder: ' + Config.TempFolder);
        Memo1.Lines.Add('Input folder: ' + Config.InputFolder);
    
        Categories := XMLConfig.Categories;
    
        for I := 0 to Categories.Count - 1 do
        begin
          Category := Categories.Category[I];
    
          Memo1.Lines.Add('Name: ' + Category.Name);
          Memo1.Lines.Add('Warning Distance: ' + IntToStr(Category.WarningDistance));
        end;
    
      end;
    end;

  3. #3
    Win32.Trojan.Heur.Herby
    Join Date
    Dec 2003
    Location
    Nuenen of all places
    Posts
    105
    Hoi

    Bedankt voor je antwoord, had wat gegoogled en inderdaad de binding wizard gezien. Als ik naar de gegenereerde code kijk vind ik het erg veel code om een paar regels van de xml in te lezen.

    Heb inmiddels al iets wat begint te werken, ben nog aan het uitvogelen waarom ik nog maar 1 category regel terug krijg. Ik had er twee verwacht in de repeat sectie.
    Heb even een logger gemaakt die eea netjes in een tmemo laat zien.

    Code:
    (*
    <?xml version="1.0" encoding="windows-1251" standalone="yes"?>
    <XMLConfig Application="POItool">
      <Config TempFolder="Temp" TemplateFolder="Template" InputFolder="Input" OutputFolder="Output"/>
      <Categories IconFolder="Icons">
        <Category Name="Speedcam Fixed" Icon="speedcamF.png" WarningSound="Yes" WarningDistance="150000"/>
        <Category Name="Speedcam Mobile" Icon="speedcamM.png" WarningSound="Yes" WarningDistance="150000"/>
      </Categories>
    </XMLConfig>
    *)
    Code:
    procedure TFormMain.FileReadXML;
    var
      RootNode              : IXMLNode;
      CategoriesNode        : IXMLNode;
      CategoryNode          : IXMLNode;
      I                     : Integer;
    begin
      Logger('INF', 'Reading ' + ExtractFileName(FXMLFileName));
      FXMLDoc                                             := TXMLDocument.Create(self);                // Create XML Document
      try
        FXMLDoc.FileName                                  := FXMLFileName;
        FXMLDoc.Active                                    := true;
    
    
        RootNode := FXMLDoc.ChildNodes.Nodes['XMLConfig'];
        if assigned (RootNode) and RootNode.HasAttribute('Application') then
          if RootNode.Attributes['Application'] = ApplicationName then
            begin
              Logger('RN',Format('Found XML with %s as application name',[ApplicationName]));
    
              for I := 0 to RootNode.ChildNodes.Count - 1 do
                begin
                  CategoriesNode := RootNode.ChildNodes[I];
    
                  Logger ('I', format('I=%d of %d',[I,RootNode.ChildNodes.Count - 1]));
                  Logger ('CN1', CategoriesNode.NodeName);
    
                  if Assigned(CategoriesNode) and (CategoriesNode.NodeName = 'Categories') then
                    begin
                      CategoryNode := CategoriesNode.ChildNodes.Nodes['Category'];
                      Logger ('', format('CategoriesNode Count %d',[I,CategoriesNode.ChildNodes.Count - 1]));
                      Logger ('',CategoryNode.NodeName);
    
                      repeat
                        if CategoryNode.HasAttribute('Name') then
                          Logger('','CategoryNode : ' + CategoryNode.Attributes['Name']);
    
                        CategoryNode.NextSibling;
                      until CategoryNode <> nil;
                    end;
                end;
          end;
    
      finally
    
      end;
    end;
    Resultaat:
    08:38:56:567 INF POItool started
    08:38:56:571 INF Reading POItool.xml
    08:38:56:608 RN Found XML with POItool as application name
    08:38:56:609 I I=0 of 1
    08:38:56:609 CN1 Config
    08:38:56:609 I I=1 of 1
    08:38:56:609 CN1 Categories
    08:38:56:610 CategoriesNode Count 1
    08:38:56:610 Category
    08:38:56:610 CategoryNode : Speedcam Fixed

    Ik mis hier de CategoryNode : Speedcam Mobile

    Gr
    Herby

  4. #4
    Quote Originally Posted by Herby View Post
    Als ik naar de gegenereerde code kijk vind ik het erg veel code om een paar regels van de xml in te lezen.
    Dat heb je vaak met gegenereerde code. Het voordeel is dat het gegenereerd is, dus je hoeft het niet allemaal zelf te typen.
    1+1=b

  5. #5
    Win32.Trojan.Heur.Herby
    Join Date
    Dec 2003
    Location
    Nuenen of all places
    Posts
    105
    klopt maar als je het zelf typt, snap je het over het algemeen ook wat beter

  6. #6
    Moet de until niet = zijn ipv <>.

    Heb je al een breakpoint gezet?

  7. #7
    Win32.Trojan.Heur.Herby
    Join Date
    Dec 2003
    Location
    Nuenen of all places
    Posts
    105
    Nee dan komt ie er helemaal niet meer, want dan loopt ie oneindig (cpu schiet dan naar 25% = 1 core)

    Het volgende werkt nu:

    Code:
    procedure TFormMain.FileReadXML;
    var
      RootNode              : IXMLNode;
      CategoriesNode        : IXMLNode;
      CategoryNode          : IXMLNode;
      I,J                   : Integer;
    
    begin
      Logger('INF', 'Reading ' + ExtractFileName(FXMLFileName));
      FXMLDoc                                             := TXMLDocument.Create(self);                // Create XML Document
      try
        FXMLDoc.FileName                                  := FXMLFileName;
        FXMLDoc.Active                                    := true;
    
    
        RootNode := FXMLDoc.ChildNodes.Nodes['XMLConfig'];
        if assigned (RootNode) and RootNode.HasAttribute('Application') then
          if RootNode.Attributes['Application'] = ApplicationName then
            begin
              Logger('RN',Format('Found XML with %s as application name',[ApplicationName]));
    
              for I := 0 to RootNode.ChildNodes.Count - 1 do
                begin
                  CategoriesNode := RootNode.ChildNodes[I];
    
                  Logger ('I', format('I=%d of %d',[I,RootNode.ChildNodes.Count - 1]));
                  Logger ('CN1', CategoriesNode.NodeName);
    
                  if Assigned(CategoriesNode) and (CategoriesNode.NodeName = 'Categories') then
                    begin
                      for J := 0 to CategoriesNode.ChildNodes.Count - 1 do
                        begin
                          CategoryNode := CategoriesNode.ChildNodes[J];
                          if CategoryNode.HasAttribute('Name') then
                            Logger('','CategoryNode : ' + CategoryNode.Attributes['Name']);
                        end;
                    end;
                end;
          end;
      finally
    
      end;
    end
    
    11:32:07:597 INF POItool started
    11:32:07:601 INF Reading POItool.xml
    11:32:07:636 RN Found XML with POItool as application name
    11:32:07:636 I I=0 of 1
    11:32:07:636 CN1 Config
    11:32:07:636 I I=1 of 1
    11:32:07:637 CN1 Categories
    11:32:07:637 CategoriesNode Count 1
    11:32:07:637 Category
    11:32:07:638 CategoryNode : Speedcam Fixed
    11:32:07:638 CategoryNode : Speedcam Mobile
    Last edited by Herby; 30-Jul-18 at 11:37. Reason: Paar regels verwijderd (leftovers)

  8. #8
    Win32.Trojan.Heur.Herby
    Join Date
    Dec 2003
    Location
    Nuenen of all places
    Posts
    105
    en uiteindelijk is het gelukt....

    Code:
    procedure TFormMain.FileReadXML;
    var
      RootNode              : IXMLNode;
      ChildNode             : IXMLNode;
      CategoriesNode        : IXMLNode;
      CategoryNode          : IXMLNode;
      I,J                   : Integer;
    
    begin
      Logger('INF', 'Reading ' + ExtractFileName(FXMLFileName));
      FXMLDoc                                             := TXMLDocument.Create(self);                // Create XML Document
      try
        FXMLDoc.FileName                                  := FXMLFileName;
        FXMLDoc.Active                                    := true;
    
        RootNode := FXMLDoc.ChildNodes.Nodes['XMLConfig'];
        if assigned (RootNode) and RootNode.HasAttribute('Application') then
          if RootNode.Attributes['Application'] = ApplicationName then
            begin
              Logger('INF',Format('Loading %s configuration from XML',[ApplicationName]));
              for I := 0 to RootNode.ChildNodes.Count - 1 do
                begin
                  ChildNode := RootNode.ChildNodes[I];
    
                  if Assigned(ChildNode) and (ChildNode.NodeName = 'Config') then
                    begin
                      Logger ('INF', 'Entering Config section');
                      if ChildNode.HasAttribute('TempFolder')     then Logger('','TempFolder : ' + ChildNode.Attributes['TempFolder']);
                      if ChildNode.HasAttribute('TemplateFolder') then Logger('','TemplateFolder : ' + ChildNode.Attributes['TemplateFolder']);
                      if ChildNode.HasAttribute('InputFolder')    then Logger('','InputFolder : ' + ChildNode.Attributes['InputFolder']);
                      if ChildNode.HasAttribute('OutputFolder')   then Logger('','OutputFolder : ' + ChildNode.Attributes['OutputFolder']);
                    end;
    
                  if Assigned(ChildNode) and (ChildNode.NodeName = 'Categories') then
                    begin
                      Logger ('INF', 'Entering Categories section');
                      if ChildNode.HasAttribute('IconFolder')     then Logger('','IconFolder : ' + ChildNode.Attributes['IconFolder']);
                          Logger ('INF', 'Reading each category');
                      for J := 0 to ChildNode.ChildNodes.Count - 1 do
                        begin
                          CategoryNode := ChildNode.ChildNodes[J];
                          if CategoryNode.HasAttribute('Name') then    Logger('','CategoryNode : ' + CategoryNode.Attributes['Name']);
                          if CategoryNode.HasAttribute('Icon') then    Logger('','Icon : ' + CategoryNode.Attributes['Icon']);
                          if CategoryNode.HasAttribute('WarningSound') then    Logger('','WarningSound : ' + CategoryNode.Attributes['WarningSound']);
                          if CategoryNode.HasAttribute('WarningDistance') then    Logger('','WarningDistance : ' + CategoryNode.Attributes['WarningDistance']);
                        end;
                    end;
                end;
          end;
      finally
        FXMLDoc.Active                                    := false;
    
      end;
    end;
    12:27:38:890 INF POItool started
    12:27:38:894 INF Reading POItool.xml
    12:27:38:923 INF Loading POItool configuration from XML
    12:27:38:924 INF Entering Config section
    12:27:38:924 TempFolder : Temp
    12:27:38:924 TemplateFolder : Template
    12:27:38:925 InputFolder : Input
    12:27:38:925 OutputFolder : Output
    12:27:38:925 INF Entering Categories section
    12:27:38:926 IconFolder : Icons
    12:27:38:926 INF Reading each category
    12:27:38:926 CategoryNode : Speedcam Fixed
    12:27:38:926 Icon : speedcamF.png
    12:27:38:927 WarningSound : Yes
    12:27:38:927 WarningDistance : 150000
    12:27:38:928 CategoryNode : Speedcam Mobile
    12:27:38:929 Icon : speedcamM.png
    12:27:38:929 WarningSound : Yes
    12:27:38:930 WarningDistance : 150000

  9. #9
    Nog een FXMLDoc.Free; nodig in je finally denk ik.

  10. #10
    Tenzij FXMLDoc gedeclareerd is als IXMLDocument.
    1+1=b

  11. #11
    Win32.Trojan.Heur.Herby
    Join Date
    Dec 2003
    Location
    Nuenen of all places
    Posts
    105
    Ik doe ergens anders een FXMLDoc := nil. Een Free bestaat niet bij IXMLDocument.

    Maar goed het werkt nu, ben alleen af en toe nog wat aan het schuiven met code.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •