aspose file tools*
The moose likes XML and Related Technologies and the fly likes Help with XMLConfiguration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Help with XMLConfiguration" Watch "Help with XMLConfiguration" New topic
Author

Help with XMLConfiguration

Mike Bates
Ranch Hand

Joined: Sep 19, 2009
Posts: 81
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
Bartender

Joined: Oct 14, 2005
Posts: 18911
    
    8

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

Joined: Mar 04, 2009
Posts: 417
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

Joined: Sep 19, 2009
Posts: 81
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

Joined: Mar 04, 2009
Posts: 417
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

Joined: Sep 19, 2009
Posts: 81
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
Bartender

Joined: Oct 14, 2005
Posts: 18911
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help with XMLConfiguration