Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xmltasks not working

Tags:

xml

ant

xmltask

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?

like image 627
javydreamercsw Avatar asked Dec 27 '22 13:12

javydreamercsw


2 Answers

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>
like image 184
Kreozot Avatar answered Jan 12 '23 20:01

Kreozot


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

like image 33
Ganesh Pathak Avatar answered Jan 12 '23 20:01

Ganesh Pathak