WebSphere Commerce extended XPath notation

When get requests for WebSphere Commerce nouns are processed, WebSphere Commerce uses extended XPath notation as the query language to identify which nouns to return. XPath is an industry standard language for addressing parts of an XML document, and the WebSphere Commerce extended XPath notation uses extensions to this standard.

The XPath notion is used because nouns. are defined in an XML schema and can be thought of as XML documents. WebSphere Commerce converts these nouns into a Java class called Service Data Objects (SDOs). SDO properties can be represented as attributes in simple cases such as Strings, or as elements when the SDO properties reference another SDO object. These SDO objects and XML schemas form the WebSphere Commerce logical model.


Mapping XPath notation

When we are using XPath expressions to request nouns, WebSphere Commerce does not use Java XPath APIs. WebSphere Commerce maps the XPath expression in the Get request to an SQL query that is defined in a query template file (.tpl file). The SQL query contains variables that WebSphere Commerce replaces at runtime. To map an XPath expression to an SQL query, WebSphere Commerce normalizes the XPath expression and associates the expression with an XPath key. To normalize the expression WebSphere Commerce removes the actual data values in the XPath. We can use the XPath key generator to normalize a specific XPath expression. The XPath key generator command-line utility takes an XPath expression as input and generates an XPath key. This key is used to locate the SQL query in the query template file. The following code snippet is an example of an XPath expression that is not normalized:

To normalize this query, WebSphere Commerce removes the value for the PartNumber. The following code demonstrates the normalized form of this query:

WebSphere Commerce creates a PartNumber variable that can be used within the SQL statement that is associated with this XPath. The SQL statement is defined in a query template file. The following SQL statement demonstrates the use of the PartNumber variable. This variable, ?PartNumber? is replaced during runtime with actual data values.

For more information about the XPath key generator and normalizing XPath expressions, see Generating your XPath key using the wcs_xpathkey utility

For more information about how XPath expressions map to the SQL query template, see query template file.

We can create our own methods for querying nouns by defining our own XML mappings in a query template file. For more information about creating our own queries, see creating a query.


XPath notation structure

When we use the XPath language, ensure that the XPath matches the logical schema of the response Noun. For example, given the following noun XML:

The following XPath expression example shows how to get CatalogGroup nouns based on the name attribute:

The XPath expression matches the structure of the logical schema. The expression is composed of the following components:

For more information about the XPath elements and control parameters, see SQL parameters.


Creating XPath expressions

When creating our own XPath expressions, we can create simple and complex expressions. Typically simple XPath expressions are explicitly defined and mapped to SQL queries in the query template files. WebSphere Commerce, however, does provide another, more dynamic, way to query objects. We can use the search() function to create a more complex XPath expression to query objects. The search() function can be used to reduce the number queries that a developer needs to create. The search() function can be placed in a predicate expression that is within an XPath expression. When we use this search expression, you do not have to define each query in the query template file. WebSphere Commerce automatically generates the query at runtime based on the contents within our search expression. For more information about creating XPath expressions with the search() function, see parametric search support. When we are creating any XPath expression, use the following syntax rules and tips to help specify control parameters, root nodes, and predicate expressions:


Examples of XPath expressions

To help us create XPath expressions to query your logical models, the following sample expressions demonstrate valid simple XPath expression syntax:

In the preceding example, the XPath expression defines a query to return organization information based on the distinguished name of the organization. This expression is composed of:

In the preceding example, The expression defines a query to retrieve summary information about a catalog entry given its part number. This XPath expression is composed of:

The following code examples provide additional samples of valid XPath expressions:


Examples of query expressions with search functions

To help us create XPath expressions that use search functions to query your logical models, the following sample expressions demonstrate valid XPath expression syntax:

In this example, the XPath expression defines a query that returns CatalogGroup information based on search results. The expression identifies that WebSphere Commerce is to return information for catalog groups with either a GroupIdentifier or a Description/Name with a value 'T'. The search function specifies to search for the GroupIdentifier within the ExternalIdentifier node for the CatalogGroupIdentifier of a CatalogGroup.

In this example, the expression includes a search function with both a simple search expression and a wildcard search expression. The wildcard search, specifies to query for any catalogEntryTypeCode contained in the CatalogEntry node that has a value of 'PackageBean' or 'DynamicKitBean'. This wildcard search specifies to query all nodes within the CatalogEntry root node, regardless of the relative path of the catalogEntryTypeCode location. The simple search expression operates as shown in the previous search function example. This search expression combines with the wildcard search expression to specify that only information that matches both search expressions is to be returned. The following code examples provide more samples of valid XPath expressions with search functions:


Related concepts
Get Request and the Show Response
XPath expressions
Query template file
Data service layer query processing


Related tasks
Creating a new search expression
Creating a query