PHP addChild()Funciones

PHP SimpleXML 参考手册Manual de referencia de PHP SimpleXML

Ejemplos

Agregar un elemento hijo al elemento body y al elemento footer:

<?php
$note=<<<XML
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
XML;

$xml=new SimpleXMLElement($note);

// Add a child element to the body element
$xml->body->addChild("date","2013-01-01");

// Add a child element after the last element inside note
$footer=$xml->addChild("footer","Some footer text");

echo $xml->asXML();
?>

Ejecutar ejemplo »

Definición y uso

La función addChild() agrega un elemento hijo a un elemento SimpleXML.


Sintaxis

addChild(name,value,ns);

Parámetros Descripción
name Requerido. Especifica el nombre del elemento hijo que se va a agregar.
value Opcional. Especifica el valor del elemento hijo.
ns Opcional. Especifica el espacio de nombres del elemento hijo.

Detalles técnicos

Valor de retorno: Devuelve un objeto SimpleXMLElement que representa el elemento hijo agregado al XML.
Versión de PHP: 5.1.3+


PHP SimpleXML 参考手册Manual de referencia de PHP SimpleXML Otras extensiones