<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="domdocument.createelement" xmlns="http://docbook.org/ns/docbook">
 <refnamediv>
  <refname>DOMDocument::createElement</refname>
  <refpurpose>Create new element node</refpurpose>
 </refnamediv>
 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis role="DOMDocument">
   <modifier>public</modifier> <type class="union"><type>DOMElement</type><type>false</type></type><methodname>DOMDocument::createElement</methodname>
   <methodparam><type>string</type><parameter>localName</parameter></methodparam>
   <methodparam choice="opt"><type>string</type><parameter>value</parameter><initializer>""</initializer></methodparam>
  </methodsynopsis>
  <para>
   This function creates a new instance of class
   <classname>DOMElement</classname>. &dom.node.inserted;
  </para>
 </refsect1>
 <refsect1 role="parameters">
  &reftitle.parameters;
  <para>
   <variablelist>
    <varlistentry>
     <term><parameter>localName</parameter></term>
     <listitem>
      <para>
       The tag name of the element.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>value</parameter></term>
     <listitem>
      <para>
       The value of the element. By default, an empty element will be created.
       The value can also be set later with <link linkend="domnode.props.nodevalue">DOMElement::$nodeValue</link>.
      </para>
      <para>
       The value is used verbatim except that the &lt; and &gt; entity
       references will escaped. Note that &amp; has to be manually escaped;
       otherwise it is regarded as starting an entity reference. Also " won't be
       escaped.
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </para>
 </refsect1>
 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   Returns a new instance of class <classname>DOMElement</classname> or &false;
   if an error occurred.
  </para>
 </refsect1>
 <refsect1 role="errors">
  &reftitle.errors;
  <para>
   <variablelist>
    <varlistentry>
     <term><constant>DOM_INVALID_CHARACTER_ERR</constant></term>
     <listitem>
      <para>
       Raised if <parameter>localName</parameter> contains an invalid character.
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </para>
 </refsect1>
 <refsect1 role="examples">
  &reftitle.examples;
  <para>
   <example>
    <title>Creating a new element and inserting it as root</title>
    <programlisting role="php">
<![CDATA[
<?php

$dom = new DOMDocument('1.0', 'utf-8');

$element = $dom->createElement('test', 'This is the root element!');

// We insert the new element as root (child of the document)
$dom->appendChild($element);

echo $dom->saveXML();
?>
]]>
    </programlisting>
    &example.outputs;
    <screen role="xml">
<![CDATA[
<?xml version="1.0" encoding="utf-8"?>
<test>This is the root element!</test>
]]>
    </screen>
   </example>
  </para>
  <para>
   <example>
    <title>Passing text containing an unescaped &amp; as <parameter>value</parameter></title>
    <programlisting role="php">
<![CDATA[
<?php
$dom = new DOMDocument('1.0', 'utf-8');
$element = $dom->createElement('foo', 'me & you');
$dom->appendChild($element);
echo $dom->saveXML();
?>
]]>
    </programlisting>
    &example.outputs.similar;
    <screen>
<![CDATA[
Warning: DOMDocument::createElement(): unterminated entity reference             you in /in/BjTCg on line 4
<?xml version="1.0" encoding="utf-8"?>
<foo/>
]]>
    </screen>
   </example>
  </para>
 </refsect1>
 <refsect1 role="notes">
  &reftitle.notes;
  <note>
   <para>
    The <parameter>value</parameter> will <emphasis>not</emphasis> be escaped.
    Use <methodname>DOMDocument::createTextNode</methodname> to create a
    text node with <emphasis>escaping support</emphasis>.
   </para>
  </note>
 </refsect1>
 <refsect1 role="seealso">
  &reftitle.seealso;
  <para>
   <simplelist>
    <member><methodname>DOMNode::appendChild</methodname></member>
    <member><methodname>DOMDocument::createAttribute</methodname></member>
    <member><methodname>DOMDocument::createAttributeNS</methodname></member>
    <member><methodname>DOMDocument::createCDATASection</methodname></member>
    <member><methodname>DOMDocument::createComment</methodname></member>
    <member><methodname>DOMDocument::createDocumentFragment</methodname></member>
    <member><methodname>DOMDocument::createElementNS</methodname></member>
    <member><methodname>DOMDocument::createEntityReference</methodname></member>
    <member><methodname>DOMDocument::createProcessingInstruction</methodname></member>
    <member><methodname>DOMDocument::createTextNode</methodname></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:"~/.phpdoc/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
-->
