fonction xpath PHP ()
Définition et utilisation
fonction xpath () fonctionne sur XPath document XML requête.
En cas de succès, la fonction renvoie les objets d'un tableau. Si elle échoue, elle retourne FALSE.
grammaire
class SimpleXMLElement
{
string xpath(path)
}
{
string xpath(path)
}
参数 | 描述 |
---|---|
path | 必需。规定要在 XML 文档中搜索的 XPath 路径。 |
Exemples
fichier 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>
Code 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);
?>
Le code ci-dessus va afficher:
Array
(
[0] => SimpleXMLElement Object
(
[0] => Jani
)
)
(
[0] => SimpleXMLElement Object
(
[0] => Jani
)
)
Remplissez Manuel PHP SimpleXML Référence