Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with XMLConfiguration

 
Mike Bates
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am looking at using the Apache Commons Configuration with XML. When I save the configuration it writes out the XML twice. I know I am doing something wrong but can't figure it out. The other odd thing is that it puts out cntrl-Ms on each line (I removed them from the output.)

Here is the XML for input {readconfig4.xml}:



Here is my test code:



And here is the output {readconfigout4.xml}:



Any thoughts or guidance would be great.

Thanks
Mike
 
Paul Clapham
Sheriff
Pie
Posts: 20758
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I checked the API documentation for that XMLConfiguration constructor. It says:

Creates and loads the XML configuration from the specified resource.


Note the words "and loads" there.

As for the "cntrl-M" characters, those are also known as "carriage return" characters. They are perfectly legal whitespace in XML documents. Perhaps this software uses the system default line-endings when it writes XML, and if so then that's what you would see if you ran it on a Windows platform but not on a Unix platform.

(It's more traditional for XML software to use only "line feed" characters on all platforms, since XML parsers are supposed to normalize away the "carriage return" characters, but there's nothing wrong with either version.)
 
Leandro Coutinho
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:Note the words "and loads" there.

I was trying to solve and it was a simple solution. :banghead:
 
Mike Bates
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what you are saying is even though there is a save method


void save(Writer writer)
Save the configuration to the specified writer.


This does not work as I would expect. I thought this would save the configuration?

Mike
 
Leandro Coutinho
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Bates wrote:So what you are saying is even though there is a save method


void save(Writer writer)
Save the configuration to the specified writer.


This does not work as I would expect. I thought this would save the configuration?

Mike

You need to remove this part: config.load();
 
Mike Bates
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I understand now (a bit dense this weekend.)

So the XMLConfiguration does a config and load. The config.load I had in place, loaded the information again.

Thanks
 
Paul Clapham
Sheriff
Pie
Posts: 20758
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike Bates wrote:Ok, I understand now (a bit dense this weekend.)


No, it was just that you had already decided (incorrectly) where the problem was located. That makes it difficult to look elsewhere for the problem, even when somebody specifically points to another location.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic