我有以下任务,由于某种原因不匹配我的文件: xmltask source="nbproject/project.xml" dest="nbproject/project.xml" replace path="/project/configuration/data/class-path-extension/runtime-relative-path/text()" withText="ext/ext
<xmltask source="nbproject/project.xml" dest="nbproject/project.xml"> <replace path="/project/configuration/data/class-path-extension/runtime-relative-path/text()" withText="ext/extensions/${extension-lib.dist.jar}.jar"/> <replace path="/project/configuration/data/class-path-extension/binary-origin/text()" withText="${original.project.dir}/dist/${extension-lib.dist.jar}.jar"/> </xmltask>
这是我正在搜索的xml文件:
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <project xmlns="http://www.netbeans.org/ns/project/1"> <type>org.netbeans.modules.apisupport.project</type> <configuration> <data xmlns="http://www.netbeans.org/ns/nb-module-project/3"> . . . <class-path-extension> <runtime-relative-path>ext/extensions/Zone_x.jar</runtime-relative-path> <binary-origin>../../Simple Marauroa Java/Zone Extension/dist/Zone_y.jar</binary-origin> </class-path-extension> </data> </configuration>
我删除了对这个问题不重要的东西.在同一文件上使用NetBeans的Xpath插件分别显示ext / extensions / Zone_x.jar和../../Simple Marauroa Java / Zone Extension / dist / Zone_y.jar的匹配项,但任务看不到它们.
有任何想法吗?
问题是输入XML使用名称空间.解决方案是使用* [local-name()=’project’]而不是项目等,这意味着你需要编写<xmltask source="nbproject/project.xml" dest="nbproject/project.xml"> <replace path="/*[local-name()='project']/*[local-name()='configuration']/*[local-name()='data']/*[local-name()='class-path-extension']/*[local-name()='runtime-relative-path']/text()" withText="ext/extensions/${extension-lib.dist.jar}.jar"/> <replace path="/*[local-name()='project']/*[local-name()='configuration']/*[local-name()='data']/*[local-name()='class-path-extension']/*[local-name()='binary-origin']/text()" withText="${original.project.dir}/dist/${extension-lib.dist.jar}.jar"/> </xmltask>