3

I'm using the Apache Commons Configuration. How can I get directly a String of the XMLConfiguration without saving it to a file?

Thank you very much.

skaffman
  • 398,947
  • 96
  • 818
  • 769
Thomas
  • 225
  • 5
  • 13

2 Answers2

5

I've found the solution, it is possible via the StringWriter:

XMLConfiguration config = new XMLConfiguration();
StringWriter stringWriter = new StringWriter();
config.save(stringWriter);
System.out.println(stringWriter.toString());
Thomas
  • 225
  • 5
  • 13
1

org.apache.commons.configuration.ConfigurationUtils.toString()

public static String toString(Configuration configuration)

Get a string representation of the key/value mappings of a configuration.

Parameters:
    configuration - the configuration 
Returns:
    a string representation of the configuration
Mads Hansen
  • 63,927
  • 12
  • 112
  • 147
  • Thanks! I think I don't quite get it. Is there also a way to get the XML representation (as a string) of the configuration? I need to print the correct XML syntax of the configuration. – Thomas May 10 '11 at 09:07