php-doc-en/reference/simplexml/functions/simplexml-element-addChild.xml
Rudy Nappée 685a03b4b3 * No () in refnames
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@263467 c90b9560-bf6c-de11-be94-00142212c4b1
2008-07-24 21:54:47 +00:00

130 lines
3.3 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.7 $ -->
<refentry xml:id='function.simplexml-element-addChild' xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>SimpleXMLElement->addChild</refname>
<refpurpose>
Adds a child element to the XML node
</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<classsynopsis>
<ooclass><classname>SimpleXMLElement</classname></ooclass>
<methodsynopsis>
<type>SimpleXMLElement</type><methodname>addChild</methodname>
<methodparam><type>string</type><parameter>name</parameter></methodparam>
<methodparam choice="opt"><type>string</type><parameter>value</parameter></methodparam>
<methodparam choice="opt"><type>string</type><parameter>namespace</parameter></methodparam>
</methodsynopsis>
</classsynopsis>
<para>
Adds a child element to the node and returns a SimpleXMLElement of the child.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>name</parameter></term>
<listitem>
<para>
The name of the child element to add.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>value</parameter></term>
<listitem>
<para>
If specified, the value of the child element.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>namespace</parameter></term>
<listitem>
<para>
If specified, the namespace to which the child element belongs.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
The <literal>addChild</literal> method returns a <type>SimpleXMLElement</type>
object representing the child added to the XML node.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Add attributes and children to a SimpleXML element</title>
<programlisting role="php">
<![CDATA[
<?php
include 'example.php';
$sxe = new SimpleXMLElement($xmlstr);
$sxe->addAttribute('type', 'documentary');
$movie = $sxe->addChild('movie');
$movie->addChild('title', 'PHP2: More Parser Stories');
$movie->addChild('plot', 'This is all about the people who make it work.');
$characters = $movie->addChild('characters');
$character = $characters->addChild('character');
$character->addChild('name', 'Mr. Parser');
$character->addChild('actor', 'John Doe');
$rating = $movie->addChild('rating', '5');
$rating->addAttribute('type', 'stars');
echo $sxe->asXML();
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><xref linkend="function.simplexml-element-addAttribute" /></member>
</simplelist>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->