[fpc-pascal] OOP and XML usage
Jorge Aldo G. de F. Junior
jagfj80 at gmail.com
Sat Jan 30 16:06:00 CET 2010
using my system you can retrieve the text by a typecast
mytag.first;
mytag.findofclass(TXMLText); <- will stop the search at the first
object of specified class
If mytag.child is TXMLText Then <- to guarantee that we have found something
WriteLn((mytag.child as TXMLText).Content); <- will print the
contents of the text
or if you know the text position between the child tags
writeln((mytag.childs[0] As TXMLText).Content);
but this is a way quite harder than a simple
WriteLn(mytag.properties['ip']); <- will return the property or '' if
not set (the object constructor can setup defaults)
thats why i prefer tag properties instead of xml text...
later you can save the objects with
Var F : Text;
Begin
Assign(F, 'myfile.xml');
Rewrite(F);
WriteLn(F, MyTag.AsXML);
Close(F);
End;
2010/1/29 Graeme Geldenhuys <graemeg.lists at gmail.com>:
> Jorge Aldo G. de F. Junior wrote:
>> and actually i prefer to setup properties of objects using xml
>> properties instead of xml text
>>
>> <tcpserver ip="192.168.1.1" port="80"/> instead of
>> <tcpserver><ip>192.168.1.1</ip><port>80</port></tcpserver>
>
> Both examples are valid XML, so I don't see any issue the way I am using
> it. My previous example was just that, an example. My actual XML uses both
> tag attributes and element text. The later is mainly used for longer text
> in my xml file.
>
>
>
> Regards,
> - Graeme -
>
> --
> fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
> http://opensoft.homeip.net/fpgui/
>
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
More information about the fpc-pascal
mailing list