PHP XPath function ()
Definicja i Wykorzystanie
Funkcja XPath () działa na zapytania XPath dokumentu XML.
Jeśli się powiedzie, funkcja zwraca obiektów tablicą SimpleXMLElements. Jeśli to się nie powiedzie, to zwraca FAŁSZ.
gramatyka
class SimpleXMLElement
{
string xpath(path)
}
{
string xpath(path)
}
参数 | 描述 |
---|---|
path | 必需。规定要在 XML 文档中搜索的 XPath 路径。 |
Przykłady
plik 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>
Kod 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);
?>
Powyższy kod wyjścia będzie:
Array
(
[0] => SimpleXMLElement Object
(
[0] => Jani
)
)
(
[0] => SimpleXMLElement Object
(
[0] => Jani
)
)
Kompletna instrukcja PHP SimpleXML Reference