PHP xpath() functie
Definitie en gebruik
De xpath() functie voert een XPath-query uit op het XML-document.
Lijst van SimpleXMLElement objecten retourneren als succesvol. Retourneert false bij falen.
Syntax
class SimpleXMLElement { string xpath(pad) }
Parameters | Beschrijving |
---|---|
pad | Verplicht. XPath Pad. |
Voorbeeld
XML Bestand:
<?xml version="1.0" encoding="ISO-8859-1"?> <note> <to>George</to> <from>John</from> <heading>Herinnering</heading> <body>Vergeten het vergadering!</body> </note>
PHP Code:
<?php $xml = simplexml_load_file("test.xml"); $result = $xml->xpath("from"); print_r($result); ?>
Uitvoer:
Array ( [0] => SimpleXMLElement Object ( [0] => John ) )