Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 465
Thomas Avatar asked Aug 27 '26 06:08

Thomas


2 Answers

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());
like image 131
Thomas Avatar answered Aug 29 '26 20:08

Thomas


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
like image 44
Mads Hansen Avatar answered Aug 29 '26 19:08

Mads Hansen