Possible Duplicate:
Pass semicolon in Ant as a parameter
我必须从这个 xml 属性标记中读取这个 XE
<databases key="Test" type=".configdb">
<dbname>test</dbname>
<driver type=".dbdriver">
<attributes>localhost;1521;XE;false</attributes>
<driverType>Oracle thin</driverType>
</driver>
<password>965449DE3DB045FE</password>
<user>test</user>
</databases>
使用 Ant 脚本。
看到了很多想法;但似乎都是很长的路,甚至没有到达确切的目的地。
提前致谢。
最佳答案
假设您在某个 resource.xml
中有此标记。您可以使用 scriptdef 使用 Ant 的 javascript 引擎解析 XE
片段。
build.xml:
<target name="something" ...
...
<scriptdef language="javascript" name="split">
<attribute name="input"/>
<attribute name="output"/>
values = attributes.get("input");
project.setProperty(attributes.get("output"), values.split(";")[2]);
</scriptdef>
<xmlproperty file="resource.xml"/>
<echo message="Original: ${databases.driver.attributes}"/>
<split input="${databases.driver.attributes}" output="result" />
<echo message="Split: ${result}"/>
...
</target>
运行此任务时,您将得到:
something:
[xmlproperty] Loading /home/code/resource.xml
[echo] Original: localhost;1521;XE;false
[echo] Split: XE
关于java - 使用 Ant 脚本解析 ";"分隔的 XML 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12089416/