net.uworks.andariel
Class XPath

java.lang.Object
  extended byorg.apache.tools.ant.ProjectComponent
      extended byorg.apache.tools.ant.Task
          extended bynet.uworks.andariel.XPath

public class XPath
extends org.apache.tools.ant.Task

Task definition for an ANT task that performs a XPath query on a XML file. This task uses the Saxon processor 8.X (tested with 8.5), which should be located in the same classpath as ANT.


 Usage:

   Task declaration in the project:
   
     <taskdef name="xpath" classname="net.uworks.andariel.XPath" />
   

   Task calling syntax:
    
     <xpath file="file" expression="expression" outputproperty="outputproperty" [delimiter="delimiter"] [backwardscompatible="true|false"] />
    


   Attributes:
       file                -> The filename of the XML we want to perform the query on.
       outputproperty      -> The name of the property where we want to store the result.
       delimiter           -> The delimiter character or sequence of each of the results (default is ",")
       backwardscompatible -> Set XPath 1.0 compatibility mode on or off (by default, it is false)


 Crude Example:

     
     <xpath file="build.xml" expression="/project/target/@name" outputproperty="targetNames" />
     

     This example retrieves the names of all the targets from a build.xml file.

 

Since:
Ant 1.5
Version:
$Revision: 1.1 $
Author:
Josep del Rio

Nested Class Summary
 class XPath.Namespace
           
 
Field Summary
 
Fields inherited from class org.apache.tools.ant.Task
description, location, target, taskName, taskType, wrapper
 
Fields inherited from class org.apache.tools.ant.ProjectComponent
project
 
Constructor Summary
XPath()
           
 
Method Summary
 XPath.Namespace createNamespace()
           
 void execute()
          Execute this task.
 void setBackwardscompatible(java.lang.String backwardscompatible)
          Set wether we should be compatible with XPath 1.0 or not.
 void setDelimiter(java.lang.String delimiter)
          Set the delimiter character/characters of each one of the query results.
 void setExpression(java.lang.String expression)
          Set the expression we want to perform over the XML file.
 void setFile(java.lang.String file)
          Set the filename of the XML file we want to check.
 void setOutputproperty(java.lang.String outputproperty)
          Set the name of the property were we want to store the result of the query.
 
Methods inherited from class org.apache.tools.ant.Task
getDescription, getLocation, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, maybeConfigure, perform, reconfigure, setDescription, setLocation, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
 
Methods inherited from class org.apache.tools.ant.ProjectComponent
getProject, setProject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XPath

public XPath()
Method Detail

execute

public void execute()
             throws org.apache.tools.ant.BuildException
Execute this task.

Throws:
org.apache.tools.ant.BuildException - Description of the Exception

setFile

public void setFile(java.lang.String file)
Set the filename of the XML file we want to check.

Parameters:
file - the filename of the XML file.

setExpression

public void setExpression(java.lang.String expression)
Set the expression we want to perform over the XML file.

Parameters:
expression - the XPath expression.

setOutputproperty

public void setOutputproperty(java.lang.String outputproperty)
Set the name of the property were we want to store the result of the query.

Parameters:
outputproperty - the name of the output property.

setBackwardscompatible

public void setBackwardscompatible(java.lang.String backwardscompatible)
Set wether we should be compatible with XPath 1.0 or not.

Parameters:
backwardscompatible - true or false, depending on the compatibility with XPath 1.0 (default is false)

setDelimiter

public void setDelimiter(java.lang.String delimiter)
Set the delimiter character/characters of each one of the query results.

Parameters:
delimiter - the results separator.

createNamespace

public XPath.Namespace createNamespace()