Thomas
Thomas

Reputation: 225

XMLConfiguration to String

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.

Upvotes: 3

Views: 2617

Answers (2)

Thomas
Thomas

Reputation: 225

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());

Upvotes: 5

Mads Hansen
Mads Hansen

Reputation: 66723

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

Upvotes: 1

Related Questions