I recently started using OmniXML primarily because it can be used for both Delphi and Lazarus.
I myself am a newbie when it comes to XML, and it is here that I hope that I can learn something or avoid any bad things that I may already be doing.
For this, I'm going to use another question that I have as a reference: Saving and loading Treeview using XML
In one of bummi's answers , I think he uses standard XML in Delphi, where I use OmniXML in Lazarus, so the code that he posted in his answer will not compile. Now I am working on changing 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 an XML Document
Delphi
FDOC := TXMLDocument.Create(nil);
OmniXML
FDOC := CreateXMLDoc;
(3) Release XML document
Delphi
if Assigned(FDOC) then FDOC.Free;
OmniXML
I donβt 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 automatically indented, I can not find any parameters?
(6) Active
Delphi
FDOC.Active := true;
OmniXML
I see no way to set such a property to True or False?
(7) Coding
Delphi
FDOC.Encoding := 'UTF-8';
OmniXML
Again I do not see such an opportunity?
Basically, I would like to know what the differences are between the Delphi XML and OmniXML implementations.
Are the changes I made right or not?
Properties that I cannot find, such as "Parameters" and "Encoding", how to implement this in OmniXML?
Thanks.