IBM Integration Bus, Version 9.0.0.8 Operating Systems: AIX, HP-Itanium, Linux, Solaris, Windows, z/OS

See information about the latest product version

Traversing the element tree

Use PHP methods to access element trees.

Use the following statements to traverse a message tree from an element:
getParent()
Returns the parent of the current element.
getPreviousSibling()
Returns the previous sibling of the current element.
getNextSibling()
Returns the next sibling of the current element.
getChild()
Returns the first child of the current element, whose name is given by the first parameter. The nth occurrence of that child element can be returned by specifying the second optional parameter.
getChildren()
Returns all the child elements of the current element as an array of MbsElements. If the namespace parameter is specified, the array contains only the child elements with that namespace URI.
getFirstChild()
Returns the first child of the current element.
getLastChild()
Returns the last child of the current element.

The following example shows a simple XML message and the logical tree that is created from the message. The message has been sent by using WebSphere® MQ. The logical tree diagram also shows the methods to call to navigate around the tree:

<document>
  <chapter title='Introduction'>
    Some text
  </chapter>
</document>
The diagram shows the methods that you can call to navigate around a message tree.
The tree used in this diagram is the one that is created by parsing the XML example given in this topic.
  • From the Root part of the tree, calling getFirstChild() navigates to Properties. Also from Root, calling getLastChild() returns XML.
  • From Properties, calling getParent() returns Root, and calling getNextSibling() returns MQMD.
  • From MQMD, calling getPreviousSibling() returns Properties, calling getParent() returns Root, and calling getNextSibling() returns XML.
  • From XML, calling getPreviousSibling() returns MQMD, calling getParent() returns Root, calling getFirstChild() returns document, and calling getLastChild() also returns document.
  • From document, calling getParent() returns XML, calling getFirstChild() returns chapter, and calling getLastChild() also returns chapter.
  • From chapter, calling getParent() returns document, calling getFirstChild() returns title, and calling getLastChild() returns the child that contains the message data "Some text.".
The following example shows how to use the MbsElement methods to navigate to the chapter element:
$chapter = $input_assembly->getLastChild()->getFirstChild()->getFirstChild();
The following example shows how to navigate to the chapter element by using the path syntax:
$chapter = $input_assembly->XML->document->chapter;

ac69091_.htm | Last updated Friday, 21 July 2017