I recently started using OmniXML primarily because it can be used for both Delphi and Lazarus.
I myself am a beginner when it comes to XML, and this is where I hope I can learn some things or avoid doing any bad things I may already be doing.
For this I am going to use another question I have as a reference: Saving and Loading Treeview using XML
In one of the answers by bummi, I think he is using standard XML in Delphi where I am using OmniXML in Lazarus, so the code he posted in his answer would not compile. I have it working now after changing some of the code but I need to know if the following is correct:
(1) Variable Types
Delphi
TTreeToXML = Class
private
FDOC: TXMLDocument;
FRootNode: IXMLNode;
OmniXML
TTreeToXML = Class
private
FDOC: IXMLDocument;
FRootNode: IXMLElement;
(2) Creating the XML Document
Delphi
FDOC := TXMLDocument.Create(nil);
OmniXML
FDOC := CreateXMLDoc;
(3) Freeing the XML Document
Delphi
if Assigned(FDOC) then
FDOC.Free;
OmniXML
I cannot see a way to Free the document?
(4) Attributes
Delphi
Procedure TTreeToXML.WriteNode(N: TTreeNode; ParentXN: IXMLNode);
var
CurrNode: IXMLNode;
Child: TTreeNode;
begin
CurrNode := ParentXN.AddChild(N.Text);
CurrNode.Attributes['NodeLevel'] := N.Level;
CurrNode.Attributes['Index'] := N.Index;
Child := N.getFirstChild;
while Assigned(Child) do
begin
WriteNode(Child, CurrNode);
Child := Child.getNextSibling;
end;
end;
OmniXML
Procedure TTreeToXML.WriteNode(N: TTreeNode; ParentXN: IXMLNode);
var
CurrNode: IXMLNode;
Child: TTreeNode;
begin
CurrNode := ParentXN.AddChild(N.Text);
CurrNode.Attributes.SetValue('NodeLevel', IntToStr(N.Level));
CurrNode.Attributes.SetValue('NodeIndex', IntToStr(N.Index));
Child := N.getFirstChild;
while Assigned(Child) do
begin
WriteNode(Child, CurrNode);
Child := Child.getNextSibling;
end;
end;
(5) Options
Delphi
FDOC.Options := FDOC.Options + [doNodeAutoIndent];
OmniXML
The Document is saved with indents automatically, I cannot find any options?
(6) Active
Delphi
FDOC.Active := true;
OmniXML
I see no way of setting such a property to True or False?
(7) Encoding
Delphi
FDOC.Encoding := 'UTF-8';
OmniXML
Again I see no such option?
So basically I guess I would like to know what are the differences between the Delphi XML and OmniXML implementations.
Are the changes I made the correct way of doing it or not?
The properties I cannot find such as Options and Encoding, how would I implement this in OmniXML?
Thanks.