2025-04-11 13:58:53 -04:00

85 lines
4.0 KiB
Markdown

# XPath Maven Plugin
This is a maven plugin that provides various xpath expression based goals to Maven.
## Usage
```xml
<project>
...
<build>
...
<plugins>
...
<plugin>
<groupId>com.inteligr8</groupId>
<artifactId>xpath-maven-plugin</artifactId>
<version>...</version>
<executions>
<execution>
<id>sample-xpath-test</id>
<phase>validate</phase>
<goals><goal>query-property</goal></goals>
<configuration>
<property>a.property.of.xml.to.query</property>
<xpath>/element/subelement[@attr1="constrained"]/@attr2</xpath>
<newProperty>a.new.property.to.store.attr2.value</newProperty>
</configuration>
</execution>
</executions>
</plugin>
...
</plugins>
...
</build>
...
</project>
```
## Goals
| Goal | Description |
| -------------------- | ----------- |
| `query-file` | Evaluate an xpath expression against the contents of a file, storing the result in a property. |
| `query-properties` | Evaluate an xpath expression against a set of property values, storing the results in properties. |
| `query-property` | Evaluate an xpath expression against a property value, storing the result in a property. |
### Common Configuration Properties
| Configuration Property | Data Type | Required | Default | Description |
| ---------------------- |:-----------:|:--------:| ------- | ----------- |
| `charset` | `string` | | `utf-8` | |
| `skip` | `boolean` | | `false` | |
| `verbose` | `boolean` | | `false` | |
### Goal: `query-file`
Searches the contents of the specified files based using the specified regular expressions; storing the result of the search in a property.
| Configuration Property | Data Type | Required | Default | Description |
| ---------------------- |:-----------:|:--------:| ------- | ----------- |
| `file` | `File` | Yes | | Executes against this XML file. |
| `xpath` | `String` | Yes | | Queries this xpath expression against the XML file. |
| `newProperty` | `String` | Yes | | The query result will be copied to a property with this property name. |
### Goal: `query-properties`
Queries the XML of the specified properties based on the specified xpath expression; storing the results in new properties.
| Configuration Property | Data Type | Required | Default | Description |
| ---------------------- |:----------:|:--------:| -------- | ----------- |
| `properties` | `String[]` | Yes | | Executes query against these properties which hold XML values. |
| `newPropertySuffix` | `String` | | `-xpath` | All query results will be copied to new properties with the same property name plus this suffix. |
| `xpath` | `String` | Yes | | Queries this xpath expression against those properties' XML values. |
### Goal: `query-property`
Queries the XML of the specified property based on the specified xpath expression; storing the result in a new property.
| Configuration Property | Data Type | Required | Default | Description |
| ---------------------- |:----------:|:--------:| ------- | ----------- |
| `property` | `String` | Yes | | Executes query against this property which holds an XML value. |
| `newProperty` | `String` | | | The query result will be copied to a property with this property name. If not specified, it will be the same name as the `property` with a `-xpath` suffix. |
| `xpath` | `String` | Yes | | Queries this xpath expression against the property XML value. |