PHP função xpath ()
Definição e Uso
função xpath () é executado em consulta documento XML XPath.
Se for bem sucedido, a função retorna objetos de uma matriz SimpleXMLElements. Se ele falhar, ele retorna FALSE.
gramática
class SimpleXMLElement
{
string xpath(path)
}
{
string xpath(path)
}
参数 | 描述 |
---|---|
path | 必需。规定要在 XML 文档中搜索的 XPath 路径。 |
Exemplos
arquivo XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
código PHP
<?php
$xml = simplexml_load_file("test.xml");
$result = $xml->xpath("from");
print_r($result);
?>
$xml = simplexml_load_file("test.xml");
$result = $xml->xpath("from");
print_r($result);
?>
O código acima exibirá:
Array
(
[0] => SimpleXMLElement Object
(
[0] => Jani
)
)
(
[0] => SimpleXMLElement Object
(
[0] => Jani
)
)
Manual Completo PHP SimpleXML Referência