Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Best way to read an XML properties file?

Reply
Thread Tools

Best way to read an XML properties file?

 
 
Bret Schuhmacher
Guest
Posts: n/a
 
      07-10-2007
Hi all,

I hope all you Java gurus that have been around the block a time or two can
answer this simple question.

What's the easiest way to read an XML properties file of relative
complexity? I know about Properties.readFromXML, but I don't think it'll
work on my semi-complex property file.

Here's my config file:
<DW>
<dir name="c:\x\y" subdirs="true">
<mask value="*.go">
<condition value="-*.go"/>
<operation value="encrypt"/>
<key value="key1"/>
<iv value="1234123412341234"/>
<mode value="AES/CBC/PKCS5Padding"/>
<etluser>
<etlpassword>
</mask>
<mask value="txt">
<condition value=">100k"/>
<operation value="encrypt"/>
<key value="key2"/>
<iv value="1234123413241234"/>
<mode value="AES/CBC/PKCS5Padding"/>
<etluser>
<etlpassword>
</mask>
</dir>
<dir name="c:\a\b\c" subdirs="true">
<mask value="*.txt">
<operation value="encrypt"/>
<key value="key3"/>
<iv value="6789678967896789"/>
<mode value="AES/CBC/PKCS5Padding"/>
<etluser>
<etlpassword>
</mask>
<mask value="*.enc">
<operation value="decrypt"/>
<key value="key4"/>
<iv value="1234123412341234"/>
<mode value="AES/CBC/PKCS5Padding"/>
<etluser>
<etlpassword>
</mask>
</dir>
</DW>


This is for a "DirectoryWatcher" program that will encrypt/decrypt files
that appear in the directories. I say it's semi-complex because the "dir"
element will have multiple occurrences, forming a list. So, too, does the
mask element - there are many masks to a "dir" element that I need brought
into the program as a list so I can iterate over the values.

I found http://easyconf.sourceforge.net. Are there other, better ways of
getting the values out of an XML config file other than parsing the doc
using DOM4J or equivalent?

Thanks,

Bret
 
Reply With Quote
 
 
 
 
Stefan Ram
Guest
Posts: n/a
 
      07-10-2007
"Bret Schuhmacher" <(E-Mail Removed)> writes:
>What's the easiest way to read an XML properties file of
>relative complexity?


This does not answer your question, but I have developed a
special notation for complex properties and now would like to
take this opportunity to advertise this notation and a GPL
library implementing it.

For simple cases, my DOM implements the Map and List interface:

roomFrom( "< a=b c=d x y z >" ).get( "a" )

gives b, and

roomFrom( "< a=b c=d x y z >" ).get( 0 )

gives x, assuming a preceding

import static de.dclj.ram.notation.unotal.RoomFromModule.roomFro m;

A java.io.File can be used instead of a string
so as to read the configuration from a file.

A slightly more complex example:

public class Main
{ public static void main( final java.lang.String[] args )
{
final de.dclj.ram.notation.unotal.RoomSource room =
de.dclj.ram.notation.unotal.RoomFromModule.roomFro m
(
" " +
" < < &car " +
" Chevy=< doors=4 paint=green > " +
" Ford=< doors=2 paint=purple > " +
" Nissan=< doors=3 paint=red >> " +
" < &bike " +
" < inch=26 &green > " +
" < inch=27 &purple >>> " +
" " );

java.lang.System.out.println
( room.getRoom( 0 ).getRoom( "Ford" ).get( "doors" ));

java.lang.System.out.println
( room.getRoom( 0 ).getType() );

java.lang.System.out.println
( room.getRoom( 1 ).hasType( "bike" ));

for( final java.lang.Object o : room.getRoom( 1 ))
java.lang.System.out.println( o ); }}

2
car
true
< &green inch =26 >
< &purple inch =27 >

The notation is being described in

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

The library is here

http://www.purl.org/stefan_ram/pub/ram-jar

Disclaimer: The recent jar contains some debug code and is
experimental. If someone would want to use this, I can provide
a jar without the debug code and some support.

 
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
Best way to save properties (ie. text) on webcontrols for reloading(asp.net 2.0) Vili ASP .Net Web Controls 1 06-30-2006 09:46 AM
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
CompositeControls: ViewState properties w/ Mapped properties probl =?Utf-8?B?Q2hyaXN0b3BoZSBQZWlsbGV0?= ASP .Net 1 01-19-2006 09:19 AM
Making Custom Control Properties Visible in Visual Studio's Properties Palette Nathan Sokalski ASP .Net 0 10-17-2005 02:05 AM
What is the best way to make dual-way xml databinding? Stan ASP .Net 3 05-05-2005 02:07 PM



Advertisments