Is there an Ant API for reading and ant build.xml and retrieving elements from it? Specifically I want to be able to retrieve the values in a path element and be able to walk all of the elements in the path.

My purpose is to retrieve a given path and ensure that it is referenced correctly in a manifest, so that the build and the manifest match when the product goes out to production.

EDIT: Regarding the responses (and thank you for them) to use an XML API, the problem is that the build file as currently constructed is more complex than that. Namely the classpath references a different classpath and includes it and the elements referenced in the classpath are themselves defined in a properties file, so there is too much of the Ant API to reasonably recreate.

4 Answers
4

You can use the ProjectHelper class to configure your project with a buildfile. If the path you want to check is contained in a reference, then you can just get the reference from the project by its ID.

Some time we need to parse xml file in Ant script to run the java file or read some property value and more like this.
It is very easy, we can do this with tag called <xmlproperty>. This tag loads the xml file and it convert all the values of xml file in ant property value internally and we can use those value as ant property. For example

<root>
<properties>
<foo>bar</foo>
</properties>
</root>

is roughly equivalent to this into ant script file as:
<property name="root.properties.foo" value="bar"/>
and you can print this value with ${root.properties.foo}.

I don't think there's an API available, but as you are only interested in one specific element, you could just write a script that only pulls out the path element and checks them over. A SAX parser in python should be fairly easy to do this with.