php-doc-en/reference/dom/domdocument/createelementns.xml
2012-01-12 05:58:52 +00:00

189 lines
5.5 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="domdocument.createelementns" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>DOMDocument::createElementNS</refname>
<refpurpose>
Create new element node with an associated namespace
</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type>DOMElement</type><methodname>DOMDocument::createElementNS</methodname>
<methodparam><type>string</type><parameter>namespaceURI</parameter></methodparam>
<methodparam><type>string</type><parameter>qualifiedName</parameter></methodparam>
<methodparam choice="opt"><type>string</type><parameter>value</parameter></methodparam>
</methodsynopsis>
<para>
This function creates a new element node with an associated namespace.
&dom.node.inserted;
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>namespaceURI</parameter></term>
<listitem>
<para>
The URI of the namespace.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>qualifiedName</parameter></term>
<listitem>
<para>
The qualified name of the element, as <literal>prefix:tagname</literal>.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>value</parameter></term>
<listitem>
<para>
The value of the element. By default, an empty element will be created.
You can also set the value later with <link
linkend="domnode.props.nodevalue">DOMElement::$nodeValue</link>.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
The new <classname>DOMElement</classname> or &false; if an error occured.
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<para>
<variablelist>
<varlistentry>
<term><constant>DOM_INVALID_CHARACTER_ERR</constant></term>
<listitem>
<para>
Raised if <parameter>qualifiedName</parameter> contains an invalid character.
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><constant>DOM_NAMESPACE_ERR</constant></term>
<listitem>
<para>
Raised if <parameter>qualifiedName</parameter> is a maformed qualified
name.
</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->createElementNS('http://www.example.com/XFoo', 'xfoo: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"?>
<xfoo:test xmlns:xfoo="http://www.example.com/XFoo">This is the root element!</xfoo:test>
]]>
</screen>
</example>
<example>
<title>A namespace prefix example</title>
<programlisting role="php">
<![CDATA[
<?php
$doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true;
$root = $doc->createElementNS('http://www.w3.org/2005/Atom', 'element');
$doc->appendChild($root);
$root->setAttributeNS('http://www.w3.org/2000/xmlns/' ,'xmlns:g', 'http://base.google.com/ns/1.0');
$item = $doc->createElementNS('http://base.google.com/ns/1.0', 'g:item_type', 'house');
$root->appendChild($item);
echo $doc->saveXML(), "\n";
echo $item->namespaceURI, "\n"; // Outputs: http://base.google.com/ns/1.0
echo $item->prefix, "\n"; // Outputs: g
echo $item->localName, "\n"; // Outputs: item_type
?>
]]>
</programlisting>
&example.outputs;
<screen role="xml">
<![CDATA[
<?xml version="1.0" encoding="utf-8"?>
<element xmlns="http://www.w3.org/2005/Atom" xmlns:g="http://base.google.com/ns/1.0">
<g:item_type>house</g:item_type>
</element>
http://base.google.com/ns/1.0
g
item_type
]]>
</screen>
</example>
</para>
</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::createElement</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
-->