更新使用蚂蚁XML元素 [英] Updating xml elements using ant
问题描述
我有一个XSL文件,其作为用于我的应用程序的配置文件。事实上,它是一个XML文件,它有它周围包裹的元素。此文件被称为Config.xsl:
I have an XSL file, which acts as a configuration file for my application. In fact it is an XML file, which has the elements wrapped around it. This file is called Config.xsl:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.example.org/Config">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" standalone="yes" />
<xsl:template match="/">
<Config>
<Test>somevalue</Test>
<Test1>someothervalue</Test1>
</Config>
</xsl:template>
我想改变元素的Test1的一个NEWVALUE值。
I would like the change the value of element Test1 with a newvalue.
下面是我的蚂蚁code,而我使用更新的值。
Below is my ant code, which I am using to update the values.
<?xml version="1.0" encoding="UTF-8" ?>
<project name="Scripts" default="test">
<taskdef resource="net/sf/antcontrib/antcontrib.properties" />
<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask"/>
<target name="test">
<xmltask source="Config.xsl" dest="Config.xsl">
<replace path="Config/Test1/text()" withText="newvalue" />
</xmltask>
</target>
</project>
我想AP preciate如果有人可以让我知道如何让这项工作。
I would appreciate if anyone can let me know how to get this work.
推荐答案
看来你与命名空间混淆。更换任何东西之前,你必须处理它。有关详细信息如何将XML任务处理它转到<$c$c>https://today.java.net/pub/a/today/2006/11/01/xml-manipulation-using-xmltask.html#paths-and-namespaces$c$c>.但是,您可能使用此code,让我们的期望的输出:
It seems you are confused with namespace. You must handle it before replacing anything. For more details how XML Task handle it goto https://today.java.net/pub/a/today/2006/11/01/xml-manipulation-using-xmltask.html#paths-and-namespaces
. However, you may used this code to get our desired output:
输入:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.example.org/Config">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" standalone="yes"/>
<xsl:template match="/">
<Config>
<Test>somevalue</Test>
<Test1>someothervalue</Test1>
</Config>
</xsl:template>
</xsl:stylesheet>
ANT脚本:
<project name="XML-VALIDATION" default="main" basedir=".">
<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask"/>
<target name="main">
<xmltask source="config.xsl" dest="output.xml">
<replace path="//:Config/:Test1/text()">xxxxxxx</replace>
</xmltask>
</target>
</project>
输出:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.example.org/Config" version="1.0">
<xsl:output encoding="UTF-8" indent="yes" method="xml" standalone="yes" version="1.0"/>
<xsl:template match="/">
<Config>
<Test>somevalue</Test>
<Test1>xxxxxxx</Test1>
</Config>
</xsl:template>
</xsl:stylesheet>
这篇关于更新使用蚂蚁XML元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!