Search code examples
xmlxpathantxmltask

find a value of a sibling node in xml file with ant xmltask


I have the following xml block (a standard jboss web.xml file) :

<web-app>
  <servlet>
    <init-param>
      <param-name>checkInterval</param-name>
      <param-value>-1</param-value>
    </init-param>
    <init-param>
      <param-name>reloading</param-name>
      <param-value>false</param-value>
    </init-param>
    .
    .
    .
  </servlet>
</web-app>

i want to select <param-value> of <init-param> with <param-name>=checkInterval and copy it. there are multiple (different) <init-params> so i need to choose it dynamically.

I have tried the following:

<target name="default" description="description">       
        <xmltask source="web.xml" dest="web_edited.xml">
            <copy path='/web-app/servlet/init-param[param-name="checkInterval"]/param-value/text()' property='property1' />     
        </xmltask>
        <echo>${property1}</echo>

</target>

expected result is -1, but instead the property is undefined. any idea ?


Solution

  • Your XPath works fine for me, so I suspect this is a problem with ant (sorry, don't know much about that).

    I have one suggestion, though: Try knocking off the 'text()' bit from the end? It's possible that it's typing -1 as a number.