<?xml version="1.0" encoding="iso-8859-1"?> <!-- $Revision: 1.3 $ --> <!-- splitted from ./en/functions/domxml.xml, last change in rev 1.38 --> <refentry id='function.DomNode-insert-before'> <refnamediv> <refname>DomNode->insert_before</refname> <refpurpose> Inserts new node as child </refpurpose> </refnamediv> <refsect1> <title>Description</title> <methodsynopsis> <type>object</type><methodname>DomNode->insert_before</methodname> <methodparam><type>object</type><parameter>newnode</parameter></methodparam> <methodparam><type>object</type><parameter>refnode</parameter></methodparam> </methodsynopsis> <para> This function inserts the new node <parameter>newnode</parameter> right before the node <parameter>refnode</parameter>. The return value is the inserted node. If you plan to do further modifications on the appended child you must use the returned node. </para> <para> (PHP >= 4.3 only) If <parameter>newnode</parameter> already is part of a document, it will be first unlinked from its existing context. If <parameter>refnode</parameter> is NULL, then <parameter>newnode</parameter> will be inserted at the end of the list of children. </para> <para> <function>DomNode_insert_before</function> is very similar to <function>DomNode_append_child</function> as the following example shows which does the same as the example at <function>DomNode_append_child</function>. </para> <para> <example> <title>Adding a child</title> <programlisting role="php"> <![CDATA[ include("example.inc"); if(!$dom = domxml_open_mem($xmlstr)) { echo "Error while parsing the document\n"; exit; } $elements = $dom->get_elements_by_tagname("informaltable"); print_r($elements); $element = $elements[0]; $newnode = $element->insert_before($element, $element); $children = $newnode->children(); $attr = $children[1]->set_attribute("align", "left"); echo "<PRE>"; $xmlfile = $dom->dump_mem(); echo htmlentities($xmlfile); echo "</PRE>"; ]]> </programlisting> </example> </para> <para> See also <function>DomNode_append_child</function>. </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 -->