PHP attributes() functie
Definitie en gebruik
De attributes() functie haalt de eigenschappen van een SimpleXML-element op.
Deze functie biedt toegang tot de eigenschappen en waarden die in een XML-tag zijn gedefinieerd.
Syntax
class SimpleXMLElement { string attributes(ns,is_prefix) }
Parameters | Beschrijving |
---|---|
ns | Optioneel. De naamruimte van het eigenschap dat wordt doorzocht. |
is_prefix | Optioneel. Standaard is false. |
Voorbeeld
XML Bestand:
<?xml version="1.0" encoding="ISO-8859-1"?> <note> <to>George</to> <from>John</from> <heading>Herinnering</heading> <body type="small" important="low">Vergeet het vergadering niet!</body> </note>
PHP Code:
<?php $xml = simplexml_load_file("test.xml"); foreach($xml->body[0]->attributes() as $a => $b) { echo $a,'="',$b,'"'; } ?>
Uitvoer:
type="small" important="low"