|Oracle® Real User Experience Insight User's Guide
Release 11.1 for Linux x86-64
Part Number E22309-01
|PDF · Mobi · ePub|
This appendix provides detailed information about the support available within RUEI for the use of XPath queries. These can be used as part of content message, client identification, custom dimension, page and service identification definitions.
XPath (XML Path Language) is a query language that can be used to select nodes and compute values from XML documents. Within RUEI, XPath version 1.0 support is based on the
libxml2 library. A complete specification of the XPath language is available at the following location:
RUEI applies XPath matching to all traffic content, regardless of whether or not it is actually in XML format. Therefore, in order to obtain accurate results, it is strongly recommended that you ensure that all XPath expressions are executed against well-formed XHTML code. In addition, note that XPath expressions are case sensitive.
XML namespaces are used for providing uniquely named elements and attributes in an XML document. An XML instance may contain element or attribute names from more than one XML vocabulary. If each vocabulary is assigned a namespace, then the ambiguity between identically named elements or attributes can be resolved.
Within RUEI, all namespaces used in your XPath queries must be explicitly defined. If a namespace is used in a query, but is not defined, it will not work. To define a namespace, do the following:
Select Configuration, then General, Advanced settings, and then XPath namespaces. The window shown in Figure F-1 appears.
Note that this window can also be reached by clicking the Namespaces tab when specifying an XPath-based content message, custom dimension, user identification, and page and service identification definition.
Click Add new to define a new namespace, or click an existing definition to modify it. The dialog shown in Figure F-2 appears.
Specify the namespace prefix used within monitored XML document, and its corresponding base URL. The name must be unique. Note that namespaces are case sensitive. See Section F.3, "Understanding Namespaces Prefixes and URLs" for important information on the use of namespaces and prefixes. Note that the namespace definitions are global and are applied to all monitored traffic.
When ready, click Save. Any new definition, or modification to an existing definition, takes effect within a 5-minute period.
A namespace consists of a prefix (which can be considered as a form of local binding), and a URL. This specifies the location of a document that defines the actual namespace. For example,
It is important to understand that a namespace is defined by its URL (or the contents of document at that location). The prefix merely represents a reference to the namespace URL within XML nodes and elements. Hence, you can bind the same namespace to multiple prefixes, and mix these prefixes in a document. The result is that all elements will be in the same namespace because all prefixes point to the same URL.
The same prefix may be bound to a different namespace in different documents. Moreover, XML allows you to bind the same prefix to different URLs in the same document.
Consider the following example:
<parent xmlns:ns1="foo"> <child xmlns:ns2="bar"> <ns2:some_element> </child> <child xmlns:ns2="baz"> <ns2:some_element> </child> </parent>
Here, the two children nodes use two different namespaces (
baz), but use the same prefix to bind it locally. Hence, the
<some_element> node has a different meaning in each of the two children.
Imagine that you want to select the second
<some_element> node. You might consider using the XPath expression
//ns2:some_element. However, this will not work, because RUEI cannot determine if the
ns2 prefix refers to the first definition (
bar) or the second (
Now imagine that you want to match both of these nodes. One possible solution is to ignore the namespace definition altogether, and use a wildcard expression. For example:
However, this expression would find all
<some_element> nodes, even ones bound to namespaces in which you are not interested. It is important to understand that the actual prefix name is irrelevant. Because the prefix is local to the part of the document where it is defined, it does not matter which prefix you use in your XPath expression as long as it is a prefix bound to the namespace that is valid at that location. Hence, the following XPath expression
baz would match the second
<some_element> node. However, because the actual prefix specified in the XPath expression does not have to match the prefix used in the document, you could also use the following XPath expression:
bar. In this case, the XPath expression is used to find a node that is locally bound to the namespace
boo is used to refer to that namespace in the XPath expression. When RUEI loads this expression, it will reference the namespace that is pointed to by
boo (which in this case is
baz), and record that it has to find a node called
<some_element> inside the namespace
baz. At that point, the prefix is no longer required. When RUEI scans a document, each time it finds a
<some_element> element, it retrieves the current namespace through the locally defined prefix, and compares that to the namespace defined in the XPath expression. If they are both
baz, then a match is found.
In the light of the above, RUEI can be configured to extract both nodes by using the following XPath expressions:
//boo:some_element where boo=bar//hoo:some_element where hoo=baz
Consider the following XML document:
<parent xmlns:ns2="foo"> <child xmlns:ns2="bar"> <ns2:some_element> </child> </parent>
In this case, both the parent and the child node use different namespaces, but both are bound to the same prefix (
ns2). This is legal because namespaces definitions are local. To find the content of the
<some_element> node, you could use the following XPath expression:
bar (or whatever local prefix strings you want).
For convenience, you can use third-party XPath tools, such as the XPather extension for Mozilla Firefox, to create XPath expressions for use within RUEI. The XPather extension is available at the following location:
When installed, you can right-click within a page, and select the Show in XPather option. An example is shown in Figure F-3.
You can then copy the XPath expression within the XPather browser (shown in Figure F-4) and use it the basis for your XPath query with RUEI. Be aware that you should review the generated XPath expression to ensure that it confirms to the restrictions described above.
Note:If the underlying HTML code within the page is not well-formed, the XPath expression generated by XPather may not function correctly within RUEI.