FluidXml\FluidXml::query PHP Method

query() public method

public query ( $query )
    public function query(...$query)
    {
        return $this->context()->query(...$query);
    }

Usage Example

Beispiel #1
0
// $fluid = fluidify('path/to/file.xml');
$other = fluidxml($fluid->xml());
$fluid = fluidxml();
$fluid->add($other)->add(['query' => $fluid->query('//meta'), 'dom' => $dom, 'domnodes' => $dom->childNodes, 'simplexml' => $simplexml]);
// Imports a SimpleXMLElement.
/******************
 * XPath Queries. *
*******************/
/*
* XPath queries can be absolute or relative to the context over they are executed.
*/
$eggs = $food->query('//egg');
$fruits = $food->query('//fruit[@price="expensive"]');
echo "We have {$eggs->length()} eggs and {$fruits->length()} expensive fruit.\n";
echo "————————————————————————————————————————————————————————————————————————————————\n";
$book->query('//chapter')->attr('lang', 'en')->query('..')->attr('lang', 'en')->query('../title')->attr('lang', 'en');
/*
* The previous code presents a repetition: all 'setAttribute' calls are identical.
* It can be refactored taking advantage of an advanced feature of 'query'.
*/
$book->query('//chapter', '//chapters', '/book/title')->attr('lang', 'en');
/*******************************
 * Accessing The Node Content. *
********************************/
/*
* The result of a query can be accessed even as array.
* Accessing the result of a query as array performs the unwrapping of the node
* and returns a raw instance of DOMNode.
* You loose the FluidXML interface but gain direct access to the DOMNode apis.
*/
$chapters = $book->query('//chapter');
All Usage Examples Of FluidXml\FluidXml::query