ant - Get XML property when there is more than one property that matches -
i have xml file this:
<vrmlist> <vrm version="4" product="prod1" platform="windows"/> <vrm version="1" product="prod1" platform="web"/> <vrm version="6" product="prod2" platform="windows"/> </vrmlist>
the file used other purposes changing it's structure difficult. access version each item independently using <xmlproperty>
task.
example
<xmlproperty file="test.xml"/> <target name="test"> <echo>version: ${vrmlist.vrm(version)}</echo> </target>
results in
test: [echo] version: 4,1,6
what want able access properties each <vrm>
independently given product , platform can use in build file.
example of want (does not work):
<echo>${vrmlist.vrm[@product="prod1" , @platform="windows"](version)}</echo> test: [echo] version: 4
is possible?
similar question: ant xmlproperty task. happens when there more 1 tag same name?
the free, third-party xmltask library can extract xml values xpath:
build.xml
<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.xmltask"/> <xmltask> <fileset file="src.xml"/> <copy path="/vrmlist/vrm[@product='prod1' , @platform='windows']/@version" property="vrm.version"/> </xmltask> <echo>vrm.version : ${vrm.version}</echo>
output
run: [echo] vrm.version : 4
Comments
Post a Comment