Fonction PHP simplexml_import_dom()
Exemple
Prenez un nœud d'un document DOM et transformez-le en un nœud SimpleXML :
<?php
$dom=new domDocument;
$dom->loadXML("<note><to>Tove</to><from>Jani</from></note>");
$x=simplexml_import_dom($dom);
echo $x->from;
?>
Définition et utilisation
La fonction simplexml_import_dom() renvoie un objet SimpleXMLElement à partir d'un nœud DOM.
Syntaxe
simplexml_import_dom(node, classname)
Valeurs des paramètres
Parameter | Description |
---|---|
node | Required. Specifies a DOM element node |
classname | Optional. Specifies the class of the new object |
Détails techniques
Valeur de retour : | Un objet SimpleXMLElement en cas de succès. FAUX en cas d'échec |
---|---|
Version PHP : | 5+ |
Plus d'exemples
Exemple
Affichez le titre du deuxième nœud de livre dans le document DOM :
<?php
$dom=new domDocument;
$dom->loadXML("<books><book><title>Title1</title></book><book><title>Title2</title></book></books>");
$x=simplexml_import_dom($dom);
echo $x->book[1]->title;
?>
❮ Référence PHP SimpleXML