xmlTreeQuickXPath

SYNOPSIS

string[] xmlTreeQuickXPath(string xmlRaw, string xpathQuery
        [, string[] xmlns)

Parameters:

  • xmlRaw - the plain text of the XML document you want to extract information from

  • xpathQuery - the XPath expression that identifies the nodes you want to extract the data from

  • xmlns (optional) - an array of prefix=URI namespaces to use in the XPath query

Returns:

  • String values of the node from the XML document xmlRaw that match xpathQuery


DESCRIPTION
xmlTreeQuickXPath allows you to easily extract information from an unparsed 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($xpath, $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'


SEE ALSO
xmlTreeNewXPath, xmlTreeXPathExecute, xmlTreeXPathRegisterNs


Copyright © Thunderstone Software     Last updated: Apr 15 2024
Copyright © 2024 Thunderstone Software LLC. All rights reserved.