Link to home
Start Free TrialLog in
Avatar of Boogaard
BoogaardFlag for Netherlands

asked on

How to import a XML file

What do I wrong in importing a XML-file.
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, xmldom, XMLIntf, msxmldom, XMLDoc, StdCtrls;

type
  TForm1 = class(TForm)
    Memo1: TMemo;
    Button1: TButton;
    XMLDocument1: TXMLDocument;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  xmlRoot: IXMLNode;
  xmlOpdracht, xmlTarieven, xmlTariefkop: IXMLNode;
begin
  XMLDocument1.FileName := 'TEST.XML';
  XMLDocument1.Active := True;
  try
    xmlRoot := XMLDocument1.DocumentElement;
    xmlOpdracht := xmlRoot.ChildNodes.FindNode('Opdracht');
    xmlTarieven := xmlOpdracht.ChildNodes.FindNode('Tarieven');
    xmlTariefkop := xmlTarieven.ChildNodes.FindNode('Tariefkop');

    while Assigned(xmlOpdracht) do
    begin
      xmlTarieven := xmlOpdracht.ChildNodes[0];

      while Assigned(xmlTarieven) do
      begin
        xmlTariefkop := xmlTarieven.ChildNodes[0];

        while Assigned(xmlTariefkop) do
        begin
          if xmlTariefkop.NodeName = 'Factuurnetto' then Memo1.Lines.Add(xmlTariefkop.Text);
          //....
          xmlTariefkop := xmlTariefkop.NextSibling;
        end; //xmlTariefkop

        xmlTarieven := xmlTarieven.NextSibling;
      end; //xmlTarieven

      xmlOpdracht := xmlOpdracht.NextSibling;
    end; //xmlOpdracht

  finally
    XMLDocument1.Active := false;
  end;


end;

end.
included the xml-file

greetings,
Henk van den Boogaard
TEST.XML
Avatar of ebob42
ebob42
Flag of Netherlands image

What is the problem exactly? I didn't download the XML file to try, yet, but it might help to tell us what's going wrong. Do you get no information from the XML file?

Waar gaat het fout? (of wat gaat er precies mis?)
xmlTarieven := xmlOpdracht.ChildNodes[0];

will result in the first childnode, being the SoortOpdracht, to be assigned to xmlTarieven.

Next, the line

xmlTariefkop := xmlTarieven.ChildNodes[0];

will fail, since SoortOpdracht has no childnodes.
ASKER CERTIFIED SOLUTION
Avatar of ebob42
ebob42
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In the above source code, you may need to change C:\TEST.XML back to TEST.XML
Avatar of Boogaard

ASKER

Thanks for the quick answer.

In dutch:
Bedankt voor het snelle antwoord.
Ik zal werkelijk vast in dit probleem.

gr. Henk