Xojo Conferences
MBSSep2018MunichDE
XDCMay2019MiamiUSA

Searching for a more elegant solution to my xml prefs code (Real Studio network user group Mailinglist archive)

Back to the thread list
Previous thread: ANN: SQLtAlarm - Alarm monitor for SQLite Databases
Next thread: RB 2006r3 Listbox Vertical down-arrow bug


Win32 API Declares   -   Berg, Heath
  Searching for a more elegant solution to my xml prefs code   -   Kevin Windham
   RE: Searching for a more elegant solution to my xml prefs code   -   Walter Purvis
    Re: Searching for a more elegant solution to my xml prefs code   -   Kevin Windham
   Re: Searching for a more elegant solution to my xml prefs code   -   Stephen Tallent
   Re: Searching for a more elegant solution to my xml prefs code   -   Dr Gerard Hammond
   Re: Searching for a more elegant solution to my xml prefs code   -   Charles Calvert
   Re: Searching for a more elegant solution to my xml prefs code   -   Kevin Windham

Searching for a more elegant solution to my xml prefs code
Date: 02.08.06 19:39 (Wed, 2 Aug 2006 13:39:29 -0500)
From: Kevin Windham
I have some code that reads and writes my preferences to an XML file.
The writing code is pretty straight forward. It just travels down the
chain of classes that make up the data model for my prefs and asks
each class instance to add it's properties to the xml document.

The reading code however is somewhat inelegant it seems. I am using
an XMLReader to parse the prefs file and it gives events for the xml
entities as it reads them in. So in order to let each class instance
handle it's own stuff, I have the XMLReader instance pass those
events to methods in the various prefs classes that mirror the event
in the XMLReader. Then each pref class has to determine if the
current xml entity belongs to it, or to a class it contains. If it is
a class contained in the current class, then the original event is
passed on to the contained class, and the cycle continues down the
chain. The code works fine, but it seems inelegant to be duplicating
all those event methods in each class. My instinct tells me that
there is a better way to handle this, but I haven't come up with it yet.

Does anyone have any suggestions?

Thanks,
Kevin
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

RE: Searching for a more elegant solution to my xml prefs code
Date: 02.08.06 20:05 (Wed, 2 Aug 2006 15:05:41 -0400)
From: Walter Purvis
I have two probably not very helpful suggestions.

One is a vague thought that you might be able to read in the entire XML
document then have the instances use XPath to extract their specific data.

Another thought is to look at the XMLPreferences module and the
XMLDictionary that it is based on, to see if they have any ideas worth
borrowing or if you could use them instead of rolling your own.

XMLPreferences
http://homepage.mac.com/crystalballmac/software/RealBasicCode.html

XMLDictionary
http://www.tildesoft.com/Code.html


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Searching for a more elegant solution to my xml prefs code
Date: 02.08.06 20:22 (Wed, 2 Aug 2006 14:22:14 -0500)
From: Kevin Windham

On Aug 2, 2006, at 2:05 PM, Walter Purvis wrote:

> I have two probably not very helpful suggestions.
>
> One is a vague thought that you might be able to read in the entire
> XML
> document then have the instances use XPath to extract their
> specific data.

I'll look into this more when I have some time. I don't know anything
about XPath yet, and my code is working so I'm not in a hurry to
learn something new. I get the feeling that my problem is one that
has some sort of pattern based solution that has nothing to do with
the particulars of my situation. This has probably come up over and
over again in various situations, and I'm just not quite smart enough
or persistent enough to invent the elegant solution on my own.

>
> Another thought is to look at the XMLPreferences module and the
> XMLDictionary that it is based on, to see if they have any ideas worth
> borrowing or if you could use them instead of rolling your own.
>
> XMLPreferences
> http://homepage.mac.com/crystalballmac/software/RealBasicCode.html
>
> XMLDictionary
> http://www.tildesoft.com/Code.html

I did take a look at these, and they aren't really solving the same
problem. Thanks for the suggestion anyway.

Kevin
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Searching for a more elegant solution to my xml prefs code
Date: 02.08.06 20:24 (Wed, 02 Aug 2006 14:24:15 -0500)
From: Stephen Tallent

> Does anyone have any suggestions?

I would have to know a good bit more about the details to know whether
this is better or not, or simply different, but here is at least one
different way to approach it. It does sound like an odd way of using
XMLReader.

I would consider using just an XMLDocument to load the prefs and store
that somewhere and "notify" the various prefs classes that it is loaded
and ready and they can use some XPath queries to extract the nodes that
they care about.

When i have done an app with a dense enough prefs structure to merit a
bit of extra effort like this, I have created a little
Broadcaster/Listener model where any class that cared could register
itself to be notified any time prefs change (whether it be by the user
during the app running, or just the first time they are loaded off
disk). In my case they simply turn around and re-query the global prefs
XML document for their nodes and away they go.

Again, not knowing the details, I have no idea whether this would be
applicable in your case. But there it is nonetheless! ;-)

-stephen

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

Re: Searching for a more elegant solution to my xml prefs code
Date: 03.08.06 00:54 (Thu, 3 Aug 2006 09:54:48 +1000)
From: Dr Gerard Hammond
At 1:39 PM -0500 2/8/06, Kevin Windham wrote:
>I have some code that reads and writes my preferences to an XML
>file. The writing code is pretty straight forward. It just travels
>down the chain of classes that make up the data model for my prefs
>and asks each class instance to add it's properties to the xml
>document.
>
>The reading code however is somewhat inelegant it seems. I am using
>an XMLReader to parse the prefs file and it gives events for the xml
>entities as it reads them in. So in order to let each class instance
>handle it's own stuff, I have the XMLReader instance pass those
>events to methods in the various prefs classes that mirror the event
>in the XMLReader. Then each pref class has to determine if the
>current xml entity belongs to it, or to a class it contains. If it
>is a class contained in the current class, then the original event
>is passed on to the contained class, and the cycle continues down
>the chain. The code works fine, but it seems inelegant to be
>duplicating all those event methods in each class. My instinct tells
>me that there is a better way to handle this, but I haven't come up
>with it yet.
>
>Does anyone have any suggestions?


I use the pbsw XML wrappers.

http://pbsw-code.net/code/realbasic/classes/pbsw-PropertyList/

I like them.

Re: Searching for a more elegant solution to my xml prefs code
Date: 03.08.06 21:08 (Thu, 03 Aug 2006 16:08:40 -0400)
From: Charles Calvert
On 8/2/2006 2:39 PM, Kevin Windham wrote:
> I have some code that reads and writes my preferences to an XML file.
> The writing code is pretty straight forward. It just travels down the
> chain of classes that make up the data model for my prefs and asks each
> class instance to add it's properties to the xml document.

That seems sensible enough.

> The reading code however is somewhat inelegant it seems. I am using an
> XMLReader to parse the prefs file and it gives events for the xml
> entities as it reads them in. So in order to let each class instance
> handle it's own stuff, I have the XMLReader instance pass those events
> to methods in the various prefs classes that mirror the event in the
> XMLReader. Then each pref class has to determine if the current xml
> entity belongs to it, or to a class it contains.

[snip rest]

I see two potential problems here.

1. I can't be sure without seeing the code, but it sounds like your
consumer classes have some knowledge of the fact that the prefs are
stored in an XML file (e.g. because they use XMLReader events). This
isn't good. Ideally, you should be able to switch among XML, binary,
Ini, Win32 registry and Unix config storage mechanisms without having to
change anything except your prefs class.

2. You're pushing the values to your consumer classes rather than
allowing them to pull from the prefs class. The latter is generally
simpler to implement and maintain (though there are instances where this
isn't true). To accomplish this in the current context, you might need
to have your prefs class parse the entire file and then store the
contents for later querying by your consumer classes.

Re: Searching for a more elegant solution to my xml prefs code
Date: 03.08.06 22:43 (Thu, 3 Aug 2006 16:43:55 -0500)
From: Kevin Windham

On Aug 2, 2006, at 1:39 PM, Kevin Windham wrote:

> I have some code that reads and writes my preferences to an XML
> file. The writing code is pretty straight forward. It just travels
> down the chain of classes that make up the data model for my prefs
> and asks each class instance to add it's properties to the xml
> document.
>
> The reading code however is somewhat inelegant it seems. I am using
> an XMLReader to parse the prefs file and it gives events for the
> xml entities as it reads them in. So in order to let each class
> instance handle it's own stuff, I have the XMLReader instance pass
> those events to methods in the various prefs classes that mirror
> the event in the XMLReader. Then each pref class has to determine
> if the current xml entity belongs to it, or to a class it contains.
> If it is a class contained in the current class, then the original
> event is passed on to the contained class, and the cycle continues
> down the chain. The code works fine, but it seems inelegant to be
> duplicating all those event methods in each class. My instinct
> tells me that there is a better way to handle this, but I haven't
> come up with it yet.
>
> Does anyone have any suggestions?

Based on some useful advice I have received here, I switched to using
the XMLDocument class for reading instead of the XMLReader class. I
guess I was a little confused about the two different methods of
reading in an XML file that RB offers.

Now that I have an XMLDocument to work with my reading code is very
similar to my writing code. I just pass the nodes down the chain to
each class so it can handle reading it's own values from the
XMLDocument. This combined with the xql that was suggested earlier
makes the code much cleaner and easier to maintain. I feel that it
would also be easier to abstract it out further if needed in the future.

Thanks for everyone's suggestions,
Kevin
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>