The XPath support was introduced to provide an access to the result set after doing the SQL query. This allows further proccessing of the result set without quering the database again.
XPath is a W3-Standard and for further information about that, ask your preferred XSL/XML book, or http://www.w3.org/.
XML_sql2xml provides two functions for querying the result set: getXpathValue() and getXpathChildValues(). Both expect a XPath query and return the result as string or array.
getXpathValue
<?php
include_once("XML/sql2xml.php");
$sql2xmlclass = new xml_sql2xml("mysql://username:password@localhost/xmltest");
$sql2xmlclass->add("select * from bands");
$xmlstring = $sql2xmlclass->getXpathValue("/root/result/row[id = '2']/name");
?>
$xmlstring
contains:
getXpathChildValues
<?php
include_once("XML/sql2xml.php");
$sql2xmlclass = new xml_sql2xml("mysql://username:password@localhost/xmltest");
$sql2xmlclass->add("select * from bands");
$xmlstring = $sql2xmlclass->getXpathChildValues("/root/result/row[id = '2']");
?>
$xmlstring
contains:
You can insert an XPath query into an SQL query. In the example, first
a SQL query is done, in the second a SQL query done again - but the
parameter for bandsID
is taken from
the XPath expression in the curly braces. This expression is processed on
the result set of the first SQL query.
Mixed query
<?php
include_once("XML/sql2xml.php");
$sql2xmlclass = new xml_sql2xml("mysql://username:password@localhost/xmltest");
$sql2xmlclass->add("select * from bands");
$sql2xmlclass->add("select * from albums where bandsID = {/root/result/row[name = 'The Blabbers']/id}");
$xmlstring = $sql2xmlclass->getxml();
?>