Added DOM examples.

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@150076 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Ken 2004-01-29 01:23:00 +00:00
parent 9662903090
commit 8a4d57e7a1
2 changed files with 57 additions and 5 deletions

View file

@ -1,11 +1,9 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.1 $ -->
<!-- $Revision: 1.2 $ -->
<refentry id='function.simplexml-load-dom'>
<refnamediv>
<refname>simplexml_load_dom</refname>
<refpurpose>
<!-- ref.dom*xml* should really be ref.dom, but that's not written
yet, so linking to ref.domxml (kennyt) -->
Get a <literal>simplexml_element</literal> object from a
DOM node.
</refpurpose>
@ -24,7 +22,29 @@
it returns &false;.
</para>
<!-- php5 DOM isn't documented; this depends on it... :| -->
&warn.undocumented.func;
<example>
<title>Import DOM</title>
<programlisting role="php">
<![CDATA[
<?php
$dom = new domDocument;
$dom->loadXML('<books><book><title>blah</title></book></books>');
if(!$dom) {
echo 'Error while parsing the document';
exit;
}
$s = simplexml_import_dom($dom);
echo $s->book[0]->title;
?>
]]>
</programlisting>
<simpara>
This code should output:
</simpara>
<screen>blah</screen>
</example>
</refsect1>
</refentry>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.2 $ -->
<!-- $Revision: 1.3 $ -->
<reference id="ref.simplexml">
<title>SimpleXML functions</title>
<titleabbrev>SimpleXML</titleabbrev>
@ -192,6 +192,38 @@ echo $xml->asXML();
</simpara>
</example>
</para>
<para>
<example>
<title>DOM Interoperability</title>
<simpara>
PHP has a mechanism to convert XML nodes between SimpleXML
and DOM formats. This example shows how one might change
a DOM element to SimpleXML.
</simpara>
<note>
<simpara>
This will only work with DOM in PHP 5, but SimpleXML wasn't
available before that version, so you should be fine.
</simpara>
</note>
<programlisting role="php">
<![CDATA[
<?php
$dom = new domDocument;
$dom->loadXML('<books><book><title>blah</title></book></books>');
if(!$dom) {
echo 'Error while parsing the document';
exit;
}
$s = simplexml_import_dom($dom);
echo $s->book[0]->title;
?>
]]>
</programlisting>
</example>
</para>
</section>
</partintro>