I had a good news and a bad news for you. A bad news is that there is not out-of-the-box solution. The good news is that xmlproperty task is quite extendable thanks for exposing processNode() method as protected. Here's what you can do:
1. Create and compile with ant.jar (you can find one in lib subdirectory in your ant distribution or get it from Maven) on classpath the following code:
package pl.sobczyk.piotr;
import org.apache.tools.ant.taskdefs.XmlProperty;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
public class MyXmlProp extends XmlProperty{
@Override
public Object processNode(Node node, String prefix, Object container) {
if(node.hasAttributes()){
NamedNodeMap nodeAttributes = node.getAttributes();
Node nameNode = nodeAttributes.getNamedItem("name");
if(nameNode != null){
String name = nameNode.getNodeValue();
String value = node.getTextContent();
if(!value.trim().isEmpty()){
String propName = prefix + "[" + name + "]";
getProject().setProperty(propName, value);
}
}
}
return super.processNode(node, prefix, container);
}
}
2. Now you only need to make this task visible to ant. The simpliest way: create task subdirectory in directory where you have your ant script -> copy compiled MyXmlProp class with it's directory structure to task directory so you should end up with something like: task/pl/sobczyk/peter/MyXmlProp.class.
3. Import task to your ant script, you should end up with something like:
<target name="print">
<taskdef name="myxmlproperty" classname="pl.sobczyk.piotr.MyXmlProp">
<classpath>
<pathelement location="task"/>
</classpath>
</taskdef>
<myxmlproperty file="config.xml" prefix="build"/>
<echo message="name = ${build.resources.string[id]}"/>
</target>
4. Run ant, ant voila, you should see: [echo] name = id17
What we did here is defining a special fancy square brackets syntax for your specific case :-). For some more general solution task extension may be a little more complex, but everything is possible :). Good luck.