About NativeXml.pas
===================
This is a small-footprint native Delphi implementation to read and write
XML documents. It provides a fully object-oriented approach to working
with XML files, with clearly defined and Delphi-focused properties,
events and methods.
You can use this code to read and write XML documents from/to files, streams
or strings. The load routine generates events that can be used to display
load progress on the fly.
Author: Nils Haeck M.Sc. (SimDesign B.V.)
Installation
============
Simply run the installer. It will copy the files to your harddisk in a location
you specify. No actual programs are installed or registered.
You can uninstall all files by clicking UNINS000.EXE in the root or through
Start > Control panel > Add/Remove software > NativeXml [Remove]
If you want to use NativeXml in your project, follow these two simple steps:
1) Copy the NativeXml.dcu file from the Delphi4, 5, 6 or 7 directory into
your project folder.
2) Include the clause "uses NativeXml" in your unit
If you want to use NativeXml in all your projects, you can also add the
\Source folder to your library path.
Compatibility
=============
DCU versions are compatible with Delphi2, Delphi4, Delphi5, Delphi6 and
Delphi7 pro and higher versions only. Full source version is compatible
with all flavours Delphi2 through Delphi7 (so also the personal).
Help
====
You can use the included NativeXml.chm help file, the examples and the
included "interface" section in NativeXml.html to get started.
Registration
============
You can register this software at the cost of Eur 29.95 through our website.
When you register you will get:
1) Full source code instead of DCU (you will receive NativeXml.pas)
2) Message upon initialisation is removed
3) Full rights to use NativeXml in your software (one developer
license).
Please visit http://www.simdesign.nl/xml.html for more information.
License
=======
Copyright (c) 2002-2005 Simdesign, Nils Haeck
It is NOT allowed under ANY circumstances to publish or copy this code
without prior written permission of the Author!
This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
ANY KIND, either express or implied.
See for additional license info the file "LICENSE.TXT" in the root folder.
Examples
========
Usage: Simply include "NativeXml" in your "uses" clause, no need to
install a component on the component palette. Add an Edit box, Memo and
3 buttons and use code below.
Example A: Loading, saving, export of XML
=========================================
procedure TForm1.Button1Click(Sender: TObject);
var
AXmlDocument: TNativeXml;
begin
Memo1.Lines.Clear;
AXmlDocument := TNativeXml.Create;
try
AXmlDocument.LoadFromFile(Edit1.Text);
AXmlDocument.XmlFormat := xfReadable;
Memo1.Lines.Text := AXmlDocument.WriteToString;
finally
AXmlDocument.Free;
end;
end;
Example B: Access to nodes
==========================
procedure TForm1.Button2Click(Sender: TObject);
var
i, j: integer;
AXmlDocument: TNativeXml;
begin
Memo1.Lines.Clear;
AXmlDocument := TNativeXml.Create;
try
AXmlDocument.LoadFromFile(Edit1.Text);
if assigned(AXmlDocument.Root) then with AXmlDocument.Root do
for i := 0 to NodeCount - 1 do begin
Memo1.Lines.Add(Nodes[i].Name);
for j := 0 to Nodes[i].NodeCount - 1 do
Memo1.Lines.Add(' ' + Nodes[i].Nodes[j].Name);
end;
finally
AXmlDocument.Free;
end;
end;
Example C: Event driven handling
================================
procedure TForm1.Button3Click(Sender: TObject);
var
AXmlDocument: TNativeXml;
begin
Memo1.Lines.Clear;
AXmlDocument := TNativeXml.Create;
try
AXmlDocument.OnNodeNew := DoNodeNew;
AXmlDocument.OnNodeLoaded := DoNodeLoaded;
AXmlDocument.LoadFromFile(Edit1.Text);
finally
AXmlDocument.Free;
end;
end;
function TForm1.Indent(ACount: integer): string;
begin
while ACount > 0 do begin
Result := Result + ' ';
dec(ACount);
end;
end;
procedure TForm1.DoNodeNew(Sender: TObject; Node: TXmlNode);
begin
Memo1.Lines.Add(Format('New : %sName=%s', [Indent(Node.TreeDepth), Node.Name]));
end;
procedure TForm1.DoNodeLoaded(Sender: TObject; Node: TXmlNode);
begin
Memo1.Lines.Add(Format('Loaded: %sName=%s, Value=%s', [Indent(Node.TreeDepth), Node.Name, Node.ValueAsString]));
end;
====================
See also the Example1 and Example2 subfolder. The Example2 subfolder
contains a complete "GUI application" demo.