Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > by-pkgid > a34ed6838d4b29d38abd504392a4a797 > files > 482

php-manual-es-4.3.0-2mdk.noarch.rpm

<HTML
><HEAD
><TITLE
>DomNode-&#62;append_child</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE="Manual de PHP"
HREF="index.html"><LINK
REL="UP"
TITLE="Funciones de DOM XML"
HREF="ref.domxml.html"><LINK
REL="PREVIOUS"
TITLE="DomNode->add_namespace"
HREF="function.domnode-add-namespace.html"><LINK
REL="NEXT"
TITLE="DomNode->append_sibling"
HREF="function.domnode-append-sibling.html"><META
HTTP-EQUIV="Content-type"
CONTENT="text/html; charset=ISO-8859-1"></HEAD
><BODY
CLASS="refentry"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Manual de PHP</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="function.domnode-add-namespace.html"
ACCESSKEY="P"
>Anterior</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="function.domnode-append-sibling.html"
ACCESSKEY="N"
>Siguiente</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><H1
><A
NAME="function.DomNode-append-child"
></A
>DomNode-&#62;append_child</H1
><DIV
CLASS="refnamediv"
><A
NAME="AEN15904"
></A
><P
>    (no version information, might be only in CVS)</P
>DomNode-&#62;append_child&nbsp;--&nbsp;
     Adds new child at the end of the children
    </DIV
><DIV
CLASS="refsect1"
><A
NAME="AEN15907"
></A
><H2
>Description</H2
>object <B
CLASS="methodname"
>DomNode-&#62;append_child</B
> ( object newnode)<BR
></BR
><P
>&#13;     This functions appends a child to an existing list of children or creates
     a new list of children. The child can be created with e.g.
     <B
CLASS="function"
>domdocument_create_element()</B
>,
     <B
CLASS="function"
>domdocument_create_text()</B
> etc. or simply by using any
     other node.
    </P
><P
>&#13;     (PHP &#60; 4.3) Before a new child is appended it is first duplicated. Therefore the new
     child is a completely new copy which can be modified without changing the
     node which was passed to this function. If the node passed has children
     itself, they will be duplicated as well, which makes it quite easy to
     duplicate large parts of a xml document. The return value is the
     appended child. If you plan to do further modifications on the appended
     child you must use the returned node.
    </P
><P
>&#13;     (PHP &#62;= 4.3) The new child <TT
CLASS="parameter"
><I
>newnode</I
></TT
> is first 
     unlinked from its existing context, if it already existed in a document.
     Therefore the node is moved and not copies anymore. This is the behaviour 
     according to the W3C specifications. If you want to duplicate large parts
     of a xml document, use DomNode-&#62;clone_node() before appending.
    </P
><P
>&#13;     The following example will add a new element node to a fresh document
     and sets the attribute "align" to "left".
     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN15922"
></A
><P
><B
>Ejemplo 1. Adding a child</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;?php
$doc = domxml_new_doc("1.0");
$node = $doc-&#62;create_element("para");
$newnode = $doc-&#62;append_child($node);
$newnode-&#62;set_attribute("align", "left");
?&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
     The above example could also be written as the following:
     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN15925"
></A
><P
><B
>Ejemplo 2. Adding a child</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;?php
$doc = domxml_new_doc("1.0");
$node = $doc-&#62;create_element("para");
$node-&#62;set_attribute("align", "left");
$newnode = $doc-&#62;append_child($node);
?&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
     A more comples example is the one below. It first searches for a certain
     element, duplicates it including its children and adds it as a sibling.
     Finally a new attribute is added to one of the children of the new
     sibling and the whole document is dumped.
     <TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
CLASS="EXAMPLE"
><TR
><TD
><DIV
CLASS="example"
><A
NAME="AEN15928"
></A
><P
><B
>Ejemplo 3. Adding a child</B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
CELLPADDING="5"
><TR
><TD
><PRE
CLASS="php"
>&#60;?php
include("example.inc");

if(!$dom = domxml_open_mem($xmlstr)) {
  echo "Error while parsing the document\n";
  exit;
}

$elements = $dom-&#62;get_elements_by_tagname("informaltable");
print_r($elements);
$element = $elements[0];

$parent = $element-&#62;parent_node();
$newnode = $parent-&#62;append_child($element);
$children = $newnode-&#62;children();
$attr = $children[1]-&#62;set_attribute("align", "left");

echo "&#60;PRE&#62;";
$xmlfile = $dom-&#62;dump_mem();
echo htmlentities($xmlfile);
echo "&#60;/PRE&#62;";
?&#62;</PRE
></TD
></TR
></TABLE
></DIV
></TD
></TR
></TABLE
>
     The above example could also be done with
     <B
CLASS="function"
>domnode_insert_before()</B
> instead of
     <B
CLASS="function"
>domnode_append_child()</B
>.
    </P
><P
>&#13;     See also <B
CLASS="function"
>domnode_insert_before()</B
>,
              <B
CLASS="function"
>domnode_clone_node()</B
>.
    </P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="function.domnode-add-namespace.html"
ACCESSKEY="P"
>Anterior</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Inicio</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="function.domnode-append-sibling.html"
ACCESSKEY="N"
>Siguiente</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>DomNode-&#62;add_namespace</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="ref.domxml.html"
ACCESSKEY="U"
>Subir</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>DomNode-&#62;append_sibling</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>