Using XPath to specify property values

Use XPath expressions to specify custom property values.

Use XPath expressions to locate values that are otherwise difficult to specify with name-value pairs.

XPath expression
An XPath expression locates and assigns the specified value to all instances of the value in the data file that have the location specified by the XPath expression.
XPath expressions work for values that
  • are not unique within the data file, for example, the values true and false might be assigned to several variables
  • cannot be replaced everywhere in the data file with the same value
For information about XPath expressions, see the XML Path Language (XPath) Version 1.0 produced by the World Wide Web Consortium (WC3).
XPath expression syntax
The syntax of a generic XPath expression is as follows:
value_name.value
value_name.xpath=/XmlNode/Child[@attrName="value"]/XmlNode/@matchAttrName

The table provides descriptions of the XPath expression elements and are provided as a guide to create a basic XPath expression.

See the WC3 documentation on XPath language: World Wide Web Consortium (WC3).

XPath expression element Description
value_name.value Assigns a value_name to the value that you want to locate in a data file.
value_name.xpath Assigns the same value_name to the XPath expression.
.xpath Query to locate that attribute whose value is to be replaced by value_name
/XmlNode/ Selects an element node named XmlNode in the XML data file.
/XmlNode/Child Selects an element node named Child with a parent named XmlNode.
/XmlNode[@attrName="value"] Selects an element node of type XmlNode with an attribute of attrName that has a specific value.
Rules for XPath expressions used in promote.properties files
  • Do not select an element node with your XPath query.
  • The XPath expression must point to an attribute that you want to update, not to an element node in the XML file.
  • XPath queries should always end with /@attrName to target an attribute and not the node element.
  • When you configure datasources, do not use absolute paths. Specify paths that are relative to container nodes.
Example of XPath expressions in promote.properties files

The following is an example of an XPath expression that locates and updates a value in the jdbc.xml data file.

The example XPath expression looks for a DataSource with the name widgetDB and updates the J2EEResourceProperty attribute to 50000 where the name attribute is portNumber.

dbport.value=50000
dbport.xpath=//DataSource[@name='widgetDB']/J2EEResourcePropertySet/J2EEResourceProperty
[@name='portNumber']/@value

The XML data file in the following example shows an excerpt from the jdbc.xml file with the updated port number value.

<jdbc>
<RAFW_JDBCDataSources>
<DataSource
  name="widgetDB"
        >
<J2EEResourcePropertySet
  WASKey="propertySet"
	>
	<J2EEResourceProperty
    WASKey="resourceProperties"
    name="portNumber"
    required="false"
	  type="java.lang.Integer"
	  value="50000"
   >
	</J2EEResourceProperty>
	</J2EEResourcePropertySet>
</DataSource>
</RAFW_JDBCDataSources>
</jdbc>
Example of relative paths to datasources in XPath expressions
When you run the action was_common_configure_jdbc_datasources in promote mode, the starting point for the XPath expression must be the relative path to the container node. You must therefore omit the absolute path declarations /jdbc/RAFW_JDBCDataSources from the expression and start with /DataSource. For example,
<DataSource
  name="widgetDB"
        >
<J2EEResourcePropertySet
  WASKey="propertySet"
	>
	<J2EEResourceProperty
    WASKey="resourceProperties"
    name="portNumber"
    required="false"
	  type="java.lang.Integer"
	  value="50000"
   >
	</J2EEResourceProperty>
	</J2EEResourcePropertySet>
</DataSource>

Example of using an XPath expression

The following example is set in an IBM UrbanCode Deploy environment.

The example uses a WebSphere Application Server configuration file, cache.xml.

  1. Original cache.xml file:
    Original cache.xml file for WebSphere Application Server
  2. Cache resources as seen in the WebSphere Application Server console:
    Cache resource as viewed in the WebSphere Application Server console
    Servlet cache resource as viewed in the WebSphere Application Server console
  3. In IBM UrbanCode Deploy, the resources are expressed as environment property definitions on the component.
    Environment property definitions for cache resources as viewed in the IBM UrbanCode Deploy console
  4. When you generate the template, tokens are inserted into the file to represent the locations for the cache resources.
    Cache.xml file after specified values are replaced with tokens
  5. Run the Configure step to apply the template to a live cell. You can specify values for the properties. In the following dialog, 5000 is specified for objCache and 75 is specified for servletCache.
    Component Environment Properties dialog for the Configure step

The changes produced by running the configuration process are shown in the WebSphere Application Server console, as the following example shows for objCache.

Modified object cache setting viewed in the WebSphere Application Server console

You can also import the configuration data from the cell to see the changed contents of cache.xml. Note the highlighted changes.

Modified cache.xml file as read from the modified cell

Feedback