我想使用 ant 脚本以编程方式删除一大块 XML。我找到了很棒的xmltask任务,但是对于我来说,我找不到resource-ref
要删除的节点。
这是我的 XML 文档的一部分。它来自web.xml
使用标准 DTD 的文件:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="WebApp_ID"
version="3.0" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<display-name>Foo</display-name>
<resource-ref>
<description>Something Clever</description>
<res-ref-name>jdbc/foo1</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
<resource-ref>
<description>Reports Database</description>
<res-ref-name>jdbc/foo2</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
我正在尝试resource-ref
像这样删除第二个块:
<project name="test" basedir="." default="fixxml">
<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask"/>
<target name="fixxml" description="er doy">
<xmltask source="web.xml" dest="output.xml">
<remove path="/web-app/resource-ref/description[text()='Reports Database']" />
</xmltask>
</target>
</project>
但是,它不起作用。我还尝试了以下remove
语句:
<remove path="/web-app/resource-ref[2]" />
....
<remove path="//description[text()[normalize-space(.)='Reports Database']]"" />
他们都没有工作。有谁看到我的查询可能做错了什么?