Extracts information from an XML document.
xmlTreeQuickXPath(string xmlRaw, string xpathQuery
[, string[] xmlns)
Parameters:
xmlRaw
- the plain text of the xml document you want to
extract information fromxpathQuery
- the XPath expression that identifies the
nodes you want to extract the data fromxmlns
(optional) - an array of prefix=URI
namespaces to use in the XPath query
Returns:
xmlRaw
that match xpathQuery
xmlTreeQuickXPath
allows you to easily extract information from
an XML document in a one-shot function. It is intended to be used in
SQL statements to extract specific information from a field that
contains XML data.
It is essentially a one statement version of the following:
<$doc = (xmlTreeNewDocFromString($xmlRaw))>
<$xpath = (xmlTreeNewXPath($doc))>
<$nodes = (xmlTreeXPathExecute($xpathQuery))>
<loop $nodes>
<$ret = (xmlTreeGetAllContent($nodes))>
<$content = $content $ret>
</loop>
EXAMPLE
if the xmlData
field of a table has content like this:
<extraInfo>
<price>8.99</price>
<author>John Doe</author>
<isbn>978-0-06-051280-4</isbn>
</extraInfo>
Then the following SQL statement will match that row:
SELECT * from myTable where xmlTreeQuickXPath(data,
'/extraInfo/author') = 'John Doe'