フラグが何らかの値に設定されている場合にのみ場所を取得する方法はありますか?
ではありませんxmlproperty
。同じタグ名を持つ値が常に混同されるためです。しかし、xmltaskは XPath の全機能をサポートしているため、必要なことを行うことができます。
<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask">
<classpath path="xmltask.jar" />
</taskdef>
<xmltask source="${base.dir}/build/my.xml">
<copy path="/root/foo[@flag='123' or @flag='256']/@location"
property="foo.location"
append="true" propertySeparator="," />
</xmltask>
<echo>${foo.location}</echo><!-- prints in,us -->
サードパーティのタスクを絶対に使用できない場合は、単純な XSLT を使用して、必要な XML のビットだけを別のファイルに抽出することで、問題に対処することをお勧めします。
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:param name="targetFlag" />
<xsl:template name="ident" match="@*|node()">
<xsl:copy><xsl:apply-templates select="@*|node()" /></xsl:copy>
</xsl:template>
<xsl:template match="foo">
<xsl:if test="@flag = $targetFlag">
<xsl:call-template name="ident" />
</xsl:if>
</xsl:template>
</xsl:stylesheet>
xslt
タスクでこれを呼び出します
<xslt in="${base.dir}/build/my.xml" out="filtered.xml" style="extract.xsl">
<param name="targetFlag" expression="123" />
</xslt>
filtered.xml
これにより、含まれているものだけが作成されます
<root>
<foo location="in" flag="123"/>
</root>
(空白のモジュロ変更) 通常の方法で xmlproperty を使用してこれをロードできます。