2010-03-28 22:10:10 +00:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
2009-07-11 06:52:11 +00:00
|
|
|
<!-- $Revision$ -->
|
2007-12-16 13:18:08 +00:00
|
|
|
<refentry xml:id="domdocument.createelement" xmlns="http://docbook.org/ns/docbook">
|
2004-12-20 15:57:49 +00:00
|
|
|
<refnamediv>
|
2007-12-16 13:18:08 +00:00
|
|
|
<refname>DOMDocument::createElement</refname>
|
2004-12-20 15:57:49 +00:00
|
|
|
<refpurpose>Create new element node</refpurpose>
|
|
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
|
|
&reftitle.description;
|
2007-12-16 13:18:08 +00:00
|
|
|
<methodsynopsis>
|
2013-06-18 05:36:30 +00:00
|
|
|
<modifier>public</modifier> <type>DOMElement</type><methodname>DOMDocument::createElement</methodname>
|
2007-12-16 13:18:08 +00:00
|
|
|
<methodparam><type>string</type><parameter>name</parameter></methodparam>
|
|
|
|
<methodparam choice="opt"><type>string</type><parameter>value</parameter></methodparam>
|
|
|
|
</methodsynopsis>
|
2004-12-20 15:57:49 +00:00
|
|
|
<para>
|
2004-12-27 13:02:52 +00:00
|
|
|
This function creates a new instance of class
|
|
|
|
<classname>DOMElement</classname>. &dom.node.inserted;
|
2004-12-20 15:57:49 +00:00
|
|
|
</para>
|
2004-12-27 13:02:52 +00:00
|
|
|
</refsect1>
|
2004-12-20 15:57:49 +00:00
|
|
|
<refsect1 role="parameters">
|
|
|
|
&reftitle.parameters;
|
|
|
|
<para>
|
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>name</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.
|
2012-01-12 05:58:52 +00:00
|
|
|
The value can also be set later with <link
|
|
|
|
linkend="domnode.props.nodevalue">DOMElement::$nodeValue</link>.
|
2004-12-20 15:57:49 +00:00
|
|
|
</para>
|
2016-06-21 16:14:05 +00:00
|
|
|
<para>
|
|
|
|
The value is used verbatim except that the < and > entity
|
|
|
|
references will escaped. Note that & has to be manually escaped;
|
|
|
|
otherwise it is regarded as starting an entity reference. Also " won't be
|
|
|
|
escaped.
|
|
|
|
</para>
|
2004-12-20 15:57:49 +00:00
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
|
|
&reftitle.returnvalues;
|
|
|
|
<para>
|
|
|
|
Returns a new instance of class <classname>DOMElement</classname> or &false;
|
2013-01-29 01:47:09 +00:00
|
|
|
if an error occurred.
|
2004-12-20 15:57:49 +00:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
2006-09-06 20:40:41 +00:00
|
|
|
<refsect1 role="errors">
|
|
|
|
&reftitle.errors;
|
2004-12-27 13:02:52 +00:00
|
|
|
<para>
|
2005-01-02 15:36:00 +00:00
|
|
|
<variablelist>
|
|
|
|
<varlistentry>
|
|
|
|
<term><constant>DOM_INVALID_CHARACTER_ERR</constant></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
Raised if <parameter>name</parameter> contains an invalid character.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
2004-12-27 13:02:52 +00:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
2004-12-20 15:57:49 +00:00
|
|
|
<refsect1 role="examples">
|
|
|
|
&reftitle.examples;
|
|
|
|
<para>
|
|
|
|
<example>
|
|
|
|
<title>Creating a new element and inserting it as root</title>
|
|
|
|
<programlisting role="php">
|
|
|
|
<![CDATA[
|
|
|
|
<?php
|
|
|
|
|
2010-04-05 15:52:15 +00:00
|
|
|
$dom = new DOMDocument('1.0', 'utf-8');
|
2004-12-20 15:57:49 +00:00
|
|
|
|
|
|
|
$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[
|
2010-03-28 22:10:10 +00:00
|
|
|
<?xml version="1.0" encoding="utf-8"?>
|
2004-12-20 15:57:49 +00:00
|
|
|
<test>This is the root element!</test>
|
2016-06-21 16:14:05 +00:00
|
|
|
]]>
|
|
|
|
</screen>
|
|
|
|
</example>
|
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
<example>
|
|
|
|
<title>Passing text containing an unescaped & 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/>
|
2004-12-20 15:57:49 +00:00
|
|
|
]]>
|
|
|
|
</screen>
|
|
|
|
</example>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
2010-01-16 22:09:23 +00:00
|
|
|
<refsect1 role="notes">
|
|
|
|
&reftitle.notes;
|
|
|
|
<note>
|
|
|
|
<para>
|
2010-01-16 22:13:22 +00:00
|
|
|
The <parameter>value</parameter> will <emphasis>not</emphasis> be escaped.
|
2010-06-03 21:47:00 +00:00
|
|
|
Use <methodname>DOMDocument::createTextNode</methodname> to create a
|
2012-04-03 08:12:03 +00:00
|
|
|
text node with <emphasis>escaping support</emphasis>.
|
2010-01-16 22:09:23 +00:00
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
</refsect1>
|
2004-12-20 15:57:49 +00:00
|
|
|
<refsect1 role="seealso">
|
|
|
|
&reftitle.seealso;
|
|
|
|
<para>
|
|
|
|
<simplelist>
|
2009-06-08 21:01:23 +00:00
|
|
|
<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>
|
2004-12-20 15:57:49 +00:00
|
|
|
</simplelist>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
</refentry>
|
2004-05-09 15:07:48 +00:00
|
|
|
|
|
|
|
<!-- 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
|
2009-09-25 07:04:39 +00:00
|
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
2004-05-09 15:07:48 +00:00
|
|
|
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
|
|
|
|
-->
|