PHP 8.4.2 Released!

Dom\import_simplexml

(PHP 8 >= 8.4.0)

Dom\import_simplexml Gets a Dom\Attr or Dom\Element object from a SimpleXMLElement object

Beschreibung

Dom\import_simplexml(object $node): Dom\Attr|Dom\Element

This function takes the given attribute or element node (a SimpleXMLElement instance) and creates a Dom\Attr or Dom\Element node, respectively. The new Dom\Node refers to the same underlying XML node as the SimpleXMLElement.

Parameter-Liste

node

Der zu importierende Attribut- oder Elementknoten (eine Instanz von SimpleXMLElement).

Rückgabewerte

The Dom\Attr or Dom\Element.

Beispiele

Beispiel #1 Import SimpleXML into DOM and modify SimpleXML through DOM

Error handling omitted for brevity.

<?php

$sxe
= simplexml_load_string('<books><book><title>blah</title></book></books>');
$elt = Dom\import_simplexml($sxe);
$elt->setAttribute("foo", "bar");
echo
$sxe->asXML();

?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

<?xml version="1.0"?>
<books foo="bar"><book><title>blah</title></book></books>

Siehe auch

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top