通过 ant 读取键值对 XML 文件?
Read key value pairings XML file via ant?
我想读取如下 XML 文件
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/com.ibm.ws.st.core.runtimeClasspathProvider/com.ibm.worklight"/>
<classpathentry kind="con" path="com.worklight.studio.plugin.classpath.SERVER_CONTAINER"/>
<classpathentry kind="src" path="server/java"/>
<classpathentry kind="src" path="common"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" output="adapters/adp1/bin" path="adapters/agent/src"/>
<classpathentry kind="src" output="adapters/adp2/bin" path="adapters/alerts/src"/>
<classpathentry kind="src" output="adapters/adp3/bin" path="adapters/billing/src"/>
<classpathentry kind="src" output="adapters/adp4/bin" path="adapters/client/src"/>
<classpathentry kind="src" output="adapters/adp5/bin" path="adapters/category/src"/>
</classpath>
我想读取 path
的值,其中 kind
是 "src"
。我能够获得所有路径值,但不能暗示它的条件。我正在使用以下代码。
<target name="xml">
<echo>Test For Each</echo>
<for list="${classpath.classpathentry.path}" param="letter" delimiter=",">
<sequential>
<echo message="path ::: @{letter}"/>
</sequential>
</for>
</target>
所有 path
值都可以正常工作,但是我应该怎么做才能获得 path
的值,其中 kind
是 "src"
?
正如我在评论中所述,以下 XSLT 将解析 kind=src 的所有类路径条目并生成单行路径语句。
getclasspath.xslt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/classpath">
<xsl:text>path=</xsl:text>
<xsl:for-each select="classpathentry[@kind='src']">
<xsl:value-of select="@path"/>
<xsl:text>;</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
然后是下面的蚂蚁任务:
<xslt style='getclasspath.xslt' in='classpath.xml' out='classpath.properties' />
我想读取如下 XML 文件
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/com.ibm.ws.st.core.runtimeClasspathProvider/com.ibm.worklight"/>
<classpathentry kind="con" path="com.worklight.studio.plugin.classpath.SERVER_CONTAINER"/>
<classpathentry kind="src" path="server/java"/>
<classpathentry kind="src" path="common"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" output="adapters/adp1/bin" path="adapters/agent/src"/>
<classpathentry kind="src" output="adapters/adp2/bin" path="adapters/alerts/src"/>
<classpathentry kind="src" output="adapters/adp3/bin" path="adapters/billing/src"/>
<classpathentry kind="src" output="adapters/adp4/bin" path="adapters/client/src"/>
<classpathentry kind="src" output="adapters/adp5/bin" path="adapters/category/src"/>
</classpath>
我想读取 path
的值,其中 kind
是 "src"
。我能够获得所有路径值,但不能暗示它的条件。我正在使用以下代码。
<target name="xml">
<echo>Test For Each</echo>
<for list="${classpath.classpathentry.path}" param="letter" delimiter=",">
<sequential>
<echo message="path ::: @{letter}"/>
</sequential>
</for>
</target>
所有 path
值都可以正常工作,但是我应该怎么做才能获得 path
的值,其中 kind
是 "src"
?
正如我在评论中所述,以下 XSLT 将解析 kind=src 的所有类路径条目并生成单行路径语句。
getclasspath.xslt
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/classpath">
<xsl:text>path=</xsl:text>
<xsl:for-each select="classpathentry[@kind='src']">
<xsl:value-of select="@path"/>
<xsl:text>;</xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
然后是下面的蚂蚁任务:
<xslt style='getclasspath.xslt' in='classpath.xml' out='classpath.properties' />