[CONFIGURATION] Create configuration out of XML String

3 messages Options
Embed this post
Permalink
Gaurav Upadhyay

[CONFIGURATION] Create configuration out of XML String

Reply Threaded More More options
Print post
Permalink
I have a xml string and need to use commons configuration with it.

How can i create a configuration on it?

Example:

String test = "<?xml version=\"1.0\" encoding=\"utf-8\"?><username><firstname>Tom</firstname> <lastname>Jay</lastname></username>"

and i just need to create a configuration and access :

config.getString("firstname");
Ralph Goers

Re: [CONFIGURATION] Create configuration out of XML String

Reply Threaded More More options
Print post
Permalink

On Oct 8, 2009, at 4:08 AM, Gaurav Upadhyay wrote:

>
> I have a xml string and need to use commons configuration with it.
>
> How can i create a configuration on it?
>
> Example:
>
> String test = "<?xml version=\"1.0\"
> encoding=\"utf-8\"?><username><firstname>Tom</firstname>
> <lastname>Jay</lastname></username>"
>
> and i just need to create a configuration and access :
>
> config.getString("firstname");
> --

I would suggest you give this a try.

ByteArrayInputStream is = new ByteArrayInputStream(test.getBytes());
XMLConfiguration config = new XMLConfiguration();
config.setFileName("test"); // May not be necessary
config.load(is);


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Gaurav Upadhyay

Re: [CONFIGURATION] Create configuration out of XML String

Reply Threaded More More options
Print post
Permalink
Thanks, That worked...!

yippiee..!

Ralph Goers wrote:
On Oct 8, 2009, at 4:08 AM, Gaurav Upadhyay wrote:

>
> I have a xml string and need to use commons configuration with it.
>
> How can i create a configuration on it?
>
> Example:
>
> String test = "<?xml version=\"1.0\"
> encoding=\"utf-8\"?><username><firstname>Tom</firstname>
> <lastname>Jay</lastname></username>"
>
> and i just need to create a configuration and access :
>
> config.getString("firstname");
> --

I would suggest you give this a try.

ByteArrayInputStream is = new ByteArrayInputStream(test.getBytes());
XMLConfiguration config = new XMLConfiguration();
config.setFileName("test"); // May not be necessary
config.load(is);


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org