PHP xpath()Funciones
Manual de referencia completo de PHP SimpleXML
Definición y uso
La función xpath() ejecuta una consulta XPath en un documento XML.
Si tiene éxito, la función devuelve una matriz de objetos SimpleXMLElements. Si falla, devuelve FALSE.
Sintaxis
class SimpleXMLElement
{
string xpath(path)
}
{
string xpath(path)
}
| Parámetros | Descripción |
|---|---|
| path | Obligatorio. Especifica la ruta XPath que se buscará en el documento XML. |
Ejemplos
Archivo 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);
?>
El código anterior generará:
Array
(
[0] => SimpleXMLElement Object
(
[0] => Jani
)
)
(
[0] => SimpleXMLElement Object
(
[0] => Jani
)
)
Manual de referencia completo de PHP SimpleXMLOtras extensiones