JJBoss
JJBoss

Reputation: 1

Parsing xml using ant

I have an xml like below.

<?xml version="1.0" encoding="UTF-8"?>
<Root>

    <environment env="dev">
        <BASE_URI>dev BASE_URI</BASE_URI>
        <PROXY_HOST>dev PROXY_HOST</PROXY_HOST>
        <PROXY_PORT>dev PROXY_PORT</PROXY_PORT>
    </environment>

    <environment env="dev2">
        <BASE_URI>test3 BASE_URI</BASE_URI>
        <PROXY_HOST>test3 PROXY_HOST</PROXY_HOST>
        <PROXY_PORT>test3 PROXY_PORT</PROXY_PORT>
    </environment>

</Root>

From ant, i will take the env as the input and i need to read all the properties of it and write to a file.

Upvotes: 0

Views: 687

Answers (2)

Eugene
Eugene

Reputation: 530

I'm not clear what you want. Do you need generate this xml based on env. variables? If so:

  • create script(let's say python or shell) which reads env. variable and generate xml file
  • add exec target to your ant script, which runs script created in a prev. step

Upvotes: 0

David W.
David W.

Reputation: 107040

Not 100% sure what you want. However, take a look at the <xmlproperty> task. This reads an XML file and turns it into a list of Ant properties (usually . formatted). Then, you can use the <echoproperties> task to print out those properties into a Java formatted properties file.

Is this what you're looking for?

If I had a bit clearer description, I could give you a coding example.

Upvotes: 1

Related Questions