Showing posts with label ant. Show all posts
Showing posts with label ant. Show all posts

Thursday, July 24, 2008

macrodef for xpathproperty in ant

No additional ant dependencies. as long as your in Java 6+

Usage:
<xpathproperty name="prop.name" value="//key/text()" file="my.xml" />

<macrodef name="xpathproperty">
<attribute name="name" />
<attribute name="value" />
<attribute name="file" />

<sequential>
<script language="javascript"> <![CDATA[
importPackage(javax.xml.xpath);
importPackage(java.io);
importClass(org.xml.sax.InputSource);

var xpathExp = XPathFactory.newInstance().newXPath().compile("@{value}");
var inputSource = new InputSource(new FileInputStream("@{file}"));

var prop = sfpricer.createTask("property");
prop.setName("@{name}");
prop.setValue(xpathExp.evaluate(inputSource));
prop.perform();

]]> </script>
</sequential>
</macrodef>