Re: entity association
Luca Padovani <[email protected]> Thu, 04 Dec 2003 18:18:33 +0100
| Newsgroups | gmane.comp.gnome.gdome |
|---|---|
| Message-ID | <1070558313.732.16.camel@giraffe> |
On Thu, 2003-12-04 at 02:37, Rafael Jannone wrote: > Say, for instance, that I have a struct like this: [...] > .. and I want to automatically create an instance of Point upon loading the > following XML: > > <point x="123" y="456" /> If I understand your problem correctly, you want two representations for the same data structure. One is an XML representation (real XML on disk, a DOM tree in memory), the other one is a C representation in terms of C structures, and you want to keep the two representations synchronized. There is no "automatic" way of doing this. The best you can do is to visit the DOM and create the C structure, and then catching DOM events so that any modification in the DOM is also reflected in the C data structure. This is _hard_ in general! An example of application doing this is gtkmathview (http://helm.cs.unibo.it/mml-widget/). The application maintains the DOM tree as well as a parallel structure of C++ objects and it uses DOM events to resync the C++ objects when the DOM changes (but not the other way around). Note that in this case the two representations are almost isomorphic, which makes the resync operation somewhat easier. However usually keeping only one of the two representations is enough. If the DOM is not suitable for you, just use the C/C++ representation while your program is running, and serialize it back to XML when you want to save your changes or want to communicate it elsewhere. There is a tool called flea that helps you solving easily the subproblem of mapping the XML into a C representation (http://www.cs.unibo.it/~lpadovan/flea/) HTH, -- luca