Skip to content

Commit d92352f

Browse files
cmb69nielsdos
andauthored
Improve dom_import_simplexml() docs (GH-3882)
* Fix dom_import_simplexml() return type (see <php/php-src#16489>) * Fix return values section, too * Update function and parameter descriptions * Clarify aliasing/view behavior and add example Co-authored-by: Niels Dossche <[email protected]>
1 parent e61b19a commit d92352f

File tree

1 file changed

+40
-7
lines changed

1 file changed

+40
-7
lines changed

reference/dom/functions/dom-import-simplexml.xml

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
<refsect1 role="description">
1212
&reftitle.description;
1313
<methodsynopsis>
14-
<type>DOMElement</type><methodname>dom_import_simplexml</methodname>
14+
<type class="union"><type>DOMAttr</type><type>DOMElement</type></type><methodname>dom_import_simplexml</methodname>
1515
<methodparam><type>object</type><parameter>node</parameter></methodparam>
1616
</methodsynopsis>
1717
<para>
18-
This function takes the node <parameter>node</parameter> of class
19-
<link linkend="ref.simplexml">SimpleXML</link> and makes it into a
20-
<classname>DOMElement</classname> node. This new object can then be used
21-
as a native <classname>DOMElement</classname> node.
18+
This function takes the given attribute or element <parameter>node</parameter> (a
19+
<classname>SimpleXMLElement</classname> instance) and creates a
20+
<classname>DOMAttr</classname> or <classname>DOMElement</classname> node, repectively.
21+
The new <classname>DOMNode</classname> refers to the same underlying XML node
22+
as the <classname>SimpleXMLElement</classname>.
2223
</para>
2324
</refsect1>
2425
<refsect1 role="parameters">
@@ -29,7 +30,7 @@
2930
<term><parameter>node</parameter></term>
3031
<listitem>
3132
<para>
32-
The <classname>SimpleXMLElement</classname> node.
33+
The attribute or element node to import (a <classname>SimpleXMLElement</classname> instance).
3334
</para>
3435
</listitem>
3536
</varlistentry>
@@ -39,7 +40,7 @@
3940
<refsect1 role="returnvalues">
4041
&reftitle.returnvalues;
4142
<para>
42-
The <classname>DOMElement</classname> node added.
43+
The <classname>DOMAttr</classname> or <classname>DOMElement</classname>.
4344
</para>
4445
</refsect1>
4546

@@ -95,6 +96,38 @@ echo $dom->saveXML();
9596
?>
9697
]]>
9798
</programlisting>
99+
&example.outputs;
100+
<screen>
101+
<![CDATA[
102+
<?xml version="1.0"?>
103+
<books><book><title>blah</title></book></books>
104+
]]>
105+
</screen>
106+
</example>
107+
<example>
108+
<title>Import SimpleXML into DOM and modify SimpleXML through DOM</title>
109+
<simpara>
110+
Error handling omitted for brevity.
111+
</simpara>
112+
<programlisting role="php">
113+
<![CDATA[
114+
<?php
115+
116+
$sxe = simplexml_load_string('<books><book><title>blah</title></book></books>');
117+
$elt = dom_import_simplexml($sxe);
118+
$elt->setAttribute("foo", "bar");
119+
echo $sxe->asXML();
120+
121+
?>
122+
]]>
123+
</programlisting>
124+
&example.outputs;
125+
<screen>
126+
<![CDATA[
127+
<?xml version="1.0"?>
128+
<books foo="bar"><book><title>blah</title></book></books>
129+
]]>
130+
</screen>
98131
</example>
99132
</refsect1>
100133
<refsect1 role="seealso">

0 commit comments

Comments
 (0)