[fpc-pascal] OOP and XML usage
Anthony Walter
sysrpl at gmail.com
Wed Jan 27 17:20:41 CET 2010
I've written some XML classes which expose themselves as interfaces.
Usage goes something like this:
procedure SaveSettings(const Settings: string);
var
Document: IDocument;
Filer: IFiler;
begin
Document := CreateDocument;
Filer := Document.ForceRoot('test') as IFiler;
Filer.WriteTime('time', Now);
Filer.WriteString('application', Application.ExeName);
Document.SaveToFile(Settings);
end;
<test><time>21:11:17</time><application>test.exe</application></test>
procedure ShowPerson;
var
Document: IDocument;
Root: INode;
begin
Document := CreateDocument;
Filer := Document.ForceRoot('data');
Root.ForceNode('person/age').Value = 17;
Root.FindNode('person[age = 17]').Filer.Write('Jason');
Root.Filer.Write('person/salary', 10000);
ShowMessage(Document.Text);
end;
<data><person><age>17</age><name>Jason</name><salary>10000</salary></person><data>
More information about the fpc-pascal
mailing list