xmltasks 不工作

发布于 2024-12-08 16:59:05 字数 1376 浏览 0 评论 0 原文

我有以下任务,但由于某种原因与我的文件不匹配:

<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 的匹配项,但任务看不到它们。

有什么想法吗?

I have the following task and for some reason is not matching my file:

<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>

Here's the xml file I'm searching:

<?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>

I removed stuff not important for this question. Using the Xpath plugin for NetBeans on the same file shows matches for ext/extensions/Zone_x.jar and ../../Simple Marauroa Java/Zone Extension/dist/Zone_y.jar respectively, but the task doesn't see them.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

毁梦 2024-12-15 16:59:05

问题在于输入 XML 使用命名空间。解决方案是使用 *[local-name()='project'] 而不是 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>

The problem is that the input XML uses namespaces. The solution is to use *[local-name()='project'] instead of project, etc., which means you need to write

<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>
燕归巢 2024-12-15 16:59:05

只需使用“:”作为本地名称空间。
前任。

替换 path="/:project/:configuration/:data/:class-path-extension/:runtime-relative-path/text()"

参考文档 = https://today.java.net/article/2006/10/31/xml-manipulation-using-xmltask

阅读部分 - 路径和命名空间

simply use ":" for local name space .
Ex.

replace path="/:project/:configuration/:data/:class-path-extension/:runtime-relative-path/text()"

Reference document = https://today.java.net/article/2006/10/31/xml-manipulation-using-xmltask

Read section - Paths and Namespaces

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文