Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > XML-based configuration files

Reply
Thread Tools

XML-based configuration files

 
 
Chris
Guest
Posts: n/a
 
      01-12-2008
Does anyone have a nice utility class they use to read/write XML-based
configuration files?

I've gotten away from Properties files because I often need a simple
data structure where 1) the values are hierarchical, 2) there can be
more than one value for a given key, and 3) the order of the values is
preserved.

So I wrote my own little replacement for Properties that has those
features, but I'm not happy with it.

It would better to use something standard and off-the-shelf. Any
suggestions?
 
Reply With Quote
 
 
 
 
Jason.Herald@gmail.com
Guest
Posts: n/a
 
      01-12-2008
On Jan 12, 5:17*pm, Chris <(E-Mail Removed)> wrote:
> Does anyone have a nice utility class they use to read/write XML-based
> configuration files?
>
> I've gotten away from Properties files because I often need a simple
> data structure where 1) the values are hierarchical, 2) there can be
> more than one value for a given key, and 3) the order of the values is
> preserved.
>
> So I wrote my own little replacement for Properties that has those
> features, but I'm not happy with it.
>
> It would better to use something standard and off-the-shelf. Any
> suggestions?


The java.util.Properties class will read in properties in xml. I
found this resource which I hope helps:
http://www.ibm.com/developerworks/ja...iger02254.html
 
Reply With Quote
 
 
 
 
Stefan Ram
Guest
Posts: n/a
 
      01-12-2008
Chris <(E-Mail Removed)> writes:
>I've gotten away from Properties files because I often need a
>simple data structure where 1) the values are hierarchical, 2)
>there can be more than one value for a given key, and


In XML, multiple value per key are not actually allowed,
this would be

<example key=value key=value1 ...></example>

They only might be simulated by direct subelements.

In Unotal, they are allow directly, and would look like

< &example key=value key=value1 ... >

>3) the order of the values is preserved.


In Unotal, it is not preserved, because all values are
deemed to form a set.

However, one can use a list of values as in

< &example key=< value value1 >>

This would preserve the sequence.

The Java-Implementation of Unotal is available as
a GPL library and is being described in

http://www.purl.org/stefan_ram/pub/junotal_tutorial

(To compile this library from the sources, currently about
three occurences of »private« needs to be removed in the
source as indicated by compiler error messages.)

 
Reply With Quote
 
ownowl
Guest
Posts: n/a
 
      01-12-2008
Chris a écrit :
> Does anyone have a nice utility class they use to read/write XML-based
> configuration files?
>
> I've gotten away from Properties files because I often need a simple
> data structure where 1) the values are hierarchical, 2) there can be
> more than one value for a given key, and 3) the order of the values is
> preserved.
>
> So I wrote my own little replacement for Properties that has those
> features, but I'm not happy with it.
>
> It would better to use something standard and off-the-shelf. Any
> suggestions?


Perhaps you could use the xstream library, that bind automatically xml
file with java objects. I think your three constraints should be
respected with this usefull library
 
Reply With Quote
 
Lew
Guest
Posts: n/a
 
      01-12-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> On Jan 12, 5:17 pm, Chris <(E-Mail Removed)> wrote:
>> Does anyone have a nice utility class they use to read/write XML-based
>> configuration files?
>>
>> I've gotten away from Properties files because I often need a simple
>> data structure where 1) the values are hierarchical, 2) there can be
>> more than one value for a given key, and 3) the order of the values is
>> preserved.
>>
>> So I wrote my own little replacement for Properties that has those
>> features, but I'm not happy with it.
>>
>> It would better to use something standard and off-the-shelf. Any
>> suggestions?

>
> The java.util.Properties class will read in properties in xml. I
> found this resource which I hope helps:
> http://www.ibm.com/developerworks/ja...iger02254.html


It's positively *amazing* how useful Javadocs can be!

I found this *incredible* reference about Properties and XML at
<http://java.sun.com/javase/6/docs/api/java/util/Properties.html>
!

It goes into a little moredetail at
<http://java.sun.com/javase/6/docs/api/java/util/Properties.html#loadFromXML(java.io.InputStream)>
and
<http://java.sun.com/javase/6/docs/api/java/util/Properties.html#storeToXML(java.io.OutputStream,%2 0java.lang.String)>
and
<http://java.sun.com/javase/6/docs/api/java/util/Properties.html#storeToXML(java.io.OutputStream,%2 0java.lang.String,%20java.lang.String)>

It's a wonder how much information one can glean from the documentation!

--
Lew
 
Reply With Quote
 
Thomas Kellerer
Guest
Posts: n/a
 
      01-12-2008
Chris wrote on 12.01.2008 23:17:
> Does anyone have a nice utility class they use to read/write XML-based
> configuration files?
>
> I've gotten away from Properties files because I often need a simple
> data structure where 1) the values are hierarchical, 2) there can be
> more than one value for a given key, and 3) the order of the values is
> preserved.
>
> So I wrote my own little replacement for Properties that has those
> features, but I'm not happy with it.
>
> It would better to use something standard and off-the-shelf. Any
> suggestions?


I use XMLDecoder and XMLEncoder to write my (configuration) objects to an xml file.

<http://java.sun.com/j2se/1.5.0/docs/api/java/beans/XMLDecoder.html>
<http://java.sun.com/j2se/1.5.0/docs/api/java/beans/XMLEncoder.html>

Thomas
 
Reply With Quote
 
EricF
Guest
Posts: n/a
 
      01-13-2008
In article <47894576$0$21150$(E-Mail Removed)-internet.fr>, ownowl <(E-Mail Removed)> wrote:
>Chris a écrit :
>> Does anyone have a nice utility class they use to read/write XML-based
>> configuration files?
>>
>> I've gotten away from Properties files because I often need a simple
>> data structure where 1) the values are hierarchical, 2) there can be
>> more than one value for a given key, and 3) the order of the values is
>> preserved.
>>
>> So I wrote my own little replacement for Properties that has those
>> features, but I'm not happy with it.
>>
>> It would better to use something standard and off-the-shelf. Any
>> suggestions?

>
>Perhaps you could use the xstream library, that bind automatically xml
>file with java objects. I think your three constraints should be
>respected with this usefull library


I hate all the XML configuration needed these days. If you can avoid xml it's
a good thing.

Sometimes you need XMLl. I agree, xstream is great for serializing/deserialing
xml to Java.

Eric
 
Reply With Quote
 
Chris
Guest
Posts: n/a
 
      01-13-2008
Lew wrote:
> (E-Mail Removed) wrote:
>> On Jan 12, 5:17 pm, Chris <(E-Mail Removed)> wrote:
>>> Does anyone have a nice utility class they use to read/write XML-based
>>> configuration files?
>>>
>>> I've gotten away from Properties files because I often need a simple
>>> data structure where 1) the values are hierarchical, 2) there can be
>>> more than one value for a given key, and 3) the order of the values is
>>> preserved.
>>>
>>> So I wrote my own little replacement for Properties that has those
>>> features, but I'm not happy with it.
>>>
>>> It would better to use something standard and off-the-shelf. Any
>>> suggestions?

>>
>> The java.util.Properties class will read in properties in xml. I
>> found this resource which I hope helps:
>> http://www.ibm.com/developerworks/ja...iger02254.html

>
> It's positively *amazing* how useful Javadocs can be!
>
> I found this *incredible* reference about Properties and XML at
> <http://java.sun.com/javase/6/docs/api/java/util/Properties.html>
> !
>
> It goes into a little moredetail at
> <http://java.sun.com/javase/6/docs/api/java/util/Properties.html#loadFromXML(java.io.InputStream)>
>
> and
> <http://java.sun.com/javase/6/docs/api/java/util/Properties.html#storeToXML(java.io.OutputStream,%2 0java.lang.String)>
>
> and
> <http://java.sun.com/javase/6/docs/api/java/util/Properties.html#storeToXML(java.io.OutputStream,%2 0java.lang.String,%20java.lang.String)>
>
>
> It's a wonder how much information one can glean from the documentation!
>


The Properties object is unsuitable because it doesn't meet the
requirements detailed above: hierarchical, multivalued, order-preserving.
 
Reply With Quote
 
Chris
Guest
Posts: n/a
 
      01-13-2008
Stefan Ram wrote:
> Chris <(E-Mail Removed)> writes:
>> I've gotten away from Properties files because I often need a
>> simple data structure where 1) the values are hierarchical, 2)
>> there can be more than one value for a given key, and

>
> In XML, multiple value per key are not actually allowed,
> this would be
>
> <example key=value key=value1 ...></example>
>
> They only might be simulated by direct subelements.
>
> In Unotal, they are allow directly, and would look like
>
> < &example key=value key=value1 ... >
>
>> 3) the order of the values is preserved.

>
> In Unotal, it is not preserved, because all values are
> deemed to form a set.
>
> However, one can use a list of values as in
>
> < &example key=< value value1 >>
>
> This would preserve the sequence.
>
> The Java-Implementation of Unotal is available as
> a GPL library and is being described in
>
> http://www.purl.org/stefan_ram/pub/junotal_tutorial
>
> (To compile this library from the sources, currently about
> three occurences of »private« needs to be removed in the
> source as indicated by compiler error messages.)
>


Thanks. Unotal looks interesting.

In my own class, I implement multiple values per key thusly:

<mykey>myvalue0</mykey>
<mykey>myvalue1</mykey>
<mykey>myvalue2</mykey>

Again, I'm not happy with this approach.
 
Reply With Quote
 
Chris
Guest
Posts: n/a
 
      01-13-2008
EricF wrote:
> In article <47894576$0$21150$(E-Mail Removed)-internet.fr>, ownowl <(E-Mail Removed)> wrote:
>> Chris a écrit :
>>> Does anyone have a nice utility class they use to read/write XML-based
>>> configuration files?
>>>
>>> I've gotten away from Properties files because I often need a simple
>>> data structure where 1) the values are hierarchical, 2) there can be
>>> more than one value for a given key, and 3) the order of the values is
>>> preserved.
>>>
>>> So I wrote my own little replacement for Properties that has those
>>> features, but I'm not happy with it.
>>>
>>> It would better to use something standard and off-the-shelf. Any
>>> suggestions?

>> Perhaps you could use the xstream library, that bind automatically xml
>> file with java objects. I think your three constraints should be
>> respected with this usefull library

>
> I hate all the XML configuration needed these days. If you can avoid xml it's
> a good thing.
>
> Sometimes you need XMLl. I agree, xstream is great for serializing/deserialing
> xml to Java.
>
> Eric


Agreed. Configuration files are a necessary evil.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Caught Exception: System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Request for the permission of type 'System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicK Mike ASP .Net 5 08-15-2007 08:57 AM
Enterprise Library exception: The configuration section securityCryptographyConfiguration is not defined in the current configuration for the AppDomain. Jess Chadwick ASP .Net 1 09-21-2006 09:18 AM
Configuration reverted to previous configuration after power loss ward@sciinc.com Cisco 0 03-03-2006 04:14 PM
Microsoft Configuration Block and Enterprise library configuration tool Mark ASP .Net 0 02-15-2006 11:27 PM
PEAP Configuration Woes - PEAP configuration help jester Cisco 1 12-20-2005 02:04 PM



Advertisments