[fpc-pascal] OOP and XML usage
Michael Van Canneyt
michael at freepascal.org
Wed Jan 27 09:51:02 CET 2010
On Wed, 27 Jan 2010, Graeme Geldenhuys wrote:
> Hi,
>
> 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
> tiOPF framework.
>
> 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.
>
> Example:
>
> -----
> <?xml version="1.0" standalone="yes"?>
> <install desc="my description" version="0.9">
> text for install element
> <eula>xxxx</eula>
> <eula lang="af">xxxxx</eula>
> </install>
> ----
>
> ...would translate to classes as follows: elements become classes and
> attributes become properties...
>
> TSetupFile
> TInstall
> TEULAList
> TEULA
>
> Interfaces section of TInstall might look like this....
>
> TInstall = class(TObject)
> public
> property Text: string... // 'text for install element'
> property Desc: string... // 'my description'
> property Version: string // '0.9'
> property EulaList: TEULAList .....
> end;
>
>
> 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?
Yes.
I use DOM to read the file, and then translate the found TDOMElement nodes to
the actual business classes.
Michael.
More information about the fpc-pascal
mailing list