Files
php-doc-ru/reference/simplexml/functions/simplexml-import-dom.xml
2024-10-25 09:41:08 +03:00

156 lines
4.4 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="utf-8"?>
<!-- EN-Revision: 62514381ff35348ffc4061b691132e36adf96210 Maintainer: aur Status: ready -->
<!-- Reviewed: no -->
<refentry xml:id="function.simplexml-import-dom" xmlns="http://docbook.org/ns/docbook">
<refnamediv>
<refname>simplexml_import_dom</refname>
<refpurpose>
Получает объект класса <literal>SimpleXMLElement</literal> из узла XML или HTML
</refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<type class="union"><type>SimpleXMLElement</type><type>null</type></type><methodname>simplexml_import_dom</methodname>
<methodparam><type>object</type><parameter>node</parameter></methodparam>
<methodparam choice="opt"><type class="union"><type>string</type><type>null</type></type><parameter>class_name</parameter><initializer>SimpleXMLElement::class</initializer></methodparam>
</methodsynopsis>
<para>
Функция берет узел документа <link linkend="book.dom">DOM</link> и превращает его
в узел SimpleXML. Затем этот новый объект может быть использован как первичный элемент
SimpleXML.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<para>
<variablelist>
<varlistentry>
<term><parameter>node</parameter></term>
<listitem>
<para>
Узел-элемент <link linkend="book.dom">DOM</link>
</para>
</listitem>
</varlistentry>
<varlistentry>
<term><parameter>class_name</parameter></term>
<listitem>
<para>
Разрешается использовать этот дополнительный параметр, чтобы функция
<function>simplexml_import_dom</function> возвращала объект заданного класса.
Этот класс должен расширять класс <type>SimpleXMLElement</type>.
</para>
</listitem>
</varlistentry>
</variablelist>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
Функция возвращает объект класса <type>SimpleXMLElement</type> или &null;, если возникла ошибка.
</para>
</refsect1>
<refsect1 role="errors">
&reftitle.errors;
<simpara>
Выбрасывает ошибку <classname>TypeError</classname>, если переданный
узел <parameter>node</parameter> не XML и не HTML.
</simpara>
</refsect1>
<refsect1 role="changelog">
&reftitle.changelog;
<informaltable>
<tgroup cols="2">
<thead>
<row>
<entry>&Version;</entry>
<entry>&Description;</entry>
</row>
</thead>
<tbody>
<row>
<entry>8.4.0</entry>
<entry>
Функция теперь выбрасывает ошибку <classname>TypeError</classname>
вместо <classname>ValueError</classname>,
если переданный узел <parameter>node</parameter> не XML и не HTML.
</entry>
</row>
</tbody>
</tgroup>
</informaltable>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<para>
<example>
<title>Импорт DOM</title>
<programlisting role="php">
<![CDATA[
<?php
$dom = new DOMDocument();
$dom->loadXML('<books><book><title>чепуха</title></book></books>');
if (!$dom) {
echo 'Ошибка при разборе документа';
exit;
}
$s = simplexml_import_dom($dom);
echo $s->book[0]->title;
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
чепуха
]]>
</screen>
</example>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<para>
<simplelist>
<member><function>dom_import_simplexml</function></member>
<member><xref linkend="simplexml.examples-basic"/></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
-->