[fpc-pascal] OOP and XML usage
graemeg.lists at gmail.com
Wed Jan 27 09:47:39 CET 2010
The small project I am working on requires reading a XML file and using
that data for various things, including building a GUI interface.
Most of my projects are database driven and uses the tiOPF framework to do
my load/saving work (plus a lot of other things).
As the title says, all my applications are normally object driven. This new
project I am working on should not be any different. One big difference
though is that it is not database driven and I don't want to bind it to
So at the moment I reading the xml file and building my own object model
based on the various elements and attributes in the XML file.
<?xml version="1.0" standalone="yes"?>
<install desc="my description" version="0.9">
text for install element
...would translate to classes as follows: elements become classes and
attributes become properties...
Interfaces section of TInstall might look like this....
TInstall = class(TObject)
property Text: string... // 'text for install element'
property Desc: string... // 'my description'
property Version: string // '0.9'
property EulaList: TEULAList .....
This makes sense to me, and this is the design I am used to following with
tiOPF based projects. But like I said, I am not using tiOPF this time and I
am working with a XML file, which I haven't worked with before.
Am I taking the right OOP approach here, or should I rather be working with
the dom unit and TXMLDocument, TXMLElement etc classes directly. At the
moment I do not require writing to the XML file, only reading. At a much
later date, I'll be writing to the XML file though.
I feel my approach of using my own specialized classes is a better fit
compared to the generic TXMLElement classes. But I just want to confirm my
thoughts and also ask...
How do other developers use XML files?
- Graeme -
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
More information about the fpc-pascal