XPath is a query language designed for use with XML documents, but you can use it with any tree structure to query contents.
WebSphere Message Broker uses XPath to select elements from the logical message tree regardless of the format of the bit stream. The terminology used in this topic is based on the terminology used in the W3C definition of XPath 1.0. For more information about XPath and the W3C definition of the XPath 1.0 standard, see XPath.
The evaluateXPath() method can be called on a MbMessage object (for absolute paths), or on a MbElement object (for relative paths). The XPath expression is passed to the method as a string parameter. A second form of this method is provided that takes an MbXPath object. This object encapsulates an XPath expression along with variable bindings and namespace mappings, if these are required.
<ns1:aaa xmlns:ns1='http://mydomain.com/namespace1' xmlns:ns2='http://mydomain.com/namespace2'> <ns2:aaa> <ns1:bbb/> </ns2:aaa> </ns1:aaa>
The namespace prefix is convenient for representing the namespace, but is meaningful only within the document that defines that mapping. The namespace URI defines the global meaning. Also, the concept of a namespace prefix is not meaningful for documents that are generated in a message flow, because a namespace URI can be assigned to a syntax element without an XMLNS mapping having been defined.
For this reason, the XMLNSC and MRM parsers expose only the namespace URI to the broker and to user code (ESQL or user-defined code). Using ESQL, you can set up your own mappings to create abbreviations to these potentially long URIs. These mappings are not related in any way to the prefixes that are defined in the XML document (although they can be the same name).
MbMessage msg = assembly.getMessage(); List chapters= (List)msg.evaluateXPath("/document/chapter"); // this returns a list of all chapters in the document (length 1) MbElement chapter = (MbElement)chapters.get(0); // the first one // values can also be extracted directly using XPath String title = (String)msg.evaluateXPath("string(/document/chapter/@title)"); String chapterText = (String)msg.evaluateXPath("string(/document/chapter/text())");