XML Examples tutorial
Using the xpath_eval() Making the resultsets with xpath_eval() function

## Preliminaries

The xpath_eval() function returns the result of applying the xpath expression to the context node. By default only the first result is returned, but supplying a third argument allows an index for the value to be specified. The default assumes a value of 1 here. A value of 0 returns an array of 0 or more elements, one for each value selected by the xpath expression.

## Examples

The examples create an internal representation of the XML image using xml_tree_doc(). An xpath_eval() statement is then executed against the internal representation of the XML document specified as /ROOT/Customers which identifies the <Customers> nodes to be processed.

The loop iterates over result for each attribute value (as CustomerID and ContactName in the first example) and retrieves the necessary values. Then the PL procedures calls result_names() and result() to send the result set to the client.

The first example will produce (when applying via ISQL utility)

    CustomerID  ContactName
    VARCHAR     VARCHAR
    ________________________

    VINET       Paul Henriot
    LILAS       Carlos Gonzalez

Here is the result from execution of the second script:

    OrderID    CustomerID    OrderDate              ProductID     Quantity
    VARCHAR    VARCHAR       VARCHAR                VARCHAR       VARCHAR
    ______________________________________________________________________

    10248      VINET         1996-07-04T00:00:00    11            12
    10248      VINET         1996-07-04T00:00:00    42            10
    10283      LILAS         1996-08-16T00:00:00    72            3

The VSP code displays the same data, but formats it into a table.

The third example shows XML entities that have returned from first execution of the xpath_eval();