• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Help with XMLConfiguration

 
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
 
Marshal
Posts: 25798
69
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.)
 
Ranch Hand
Posts: 430
  • 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: 430
  • 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
Marshal
Posts: 25798
69
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.
 
If I'd had more time, I would have written a shorter letter. -T.S. Eliot such a short, tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic