mirror of
https://github.com/php/doc-ru.git
synced 2025-08-16 18:22:04 +00:00
163 lines
4.4 KiB
XML
163 lines
4.4 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
||
<!-- EN-Revision: d92352faa89a7faf6031ecb39d48b53d70236ce3 Maintainer: aur Status: ready -->
|
||
<!-- Reviewed: no -->
|
||
<refentry xml:id="function.dom-import-simplexml" xmlns="http://docbook.org/ns/docbook">
|
||
<refnamediv>
|
||
<refname>dom_import_simplexml</refname>
|
||
<refpurpose>
|
||
Получает объект класса <classname>DOMElement</classname> из объекта
|
||
класса <classname>SimpleXMLElement</classname>
|
||
</refpurpose>
|
||
</refnamediv>
|
||
<refsect1 role="description">
|
||
&reftitle.description;
|
||
<methodsynopsis>
|
||
<type class="union"><type>DOMAttr</type><type>DOMElement</type></type><methodname>dom_import_simplexml</methodname>
|
||
<methodparam><type>object</type><parameter>node</parameter></methodparam>
|
||
</methodsynopsis>
|
||
<para>
|
||
Функция принимает заданный атрибут или элемент <parameter>node</parameter>
|
||
(экземпляр класса <classname>SimpleXMLElement</classname>) и создаёт узел <classname>DOMAttr</classname>
|
||
или <classname>DOMElement</classname>, соответственно.
|
||
Новый <classname>DOMNode</classname> ссылается на тот же базовый XML-узел,
|
||
что и <classname>SimpleXMLElement</classname>.
|
||
</para>
|
||
</refsect1>
|
||
<refsect1 role="parameters">
|
||
&reftitle.parameters;
|
||
<para>
|
||
<variablelist>
|
||
<varlistentry>
|
||
<term><parameter>node</parameter></term>
|
||
<listitem>
|
||
<para>
|
||
Узел атрибута или элемента для импорта (экземпляр <classname>SimpleXMLElement</classname>).
|
||
</para>
|
||
</listitem>
|
||
</varlistentry>
|
||
</variablelist>
|
||
</para>
|
||
</refsect1>
|
||
<refsect1 role="returnvalues">
|
||
&reftitle.returnvalues;
|
||
<para>
|
||
Функция возвращает <classname>DOMAttr</classname> или <classname>DOMElement</classname>.
|
||
</para>
|
||
</refsect1>
|
||
|
||
<refsect1 role="changelog">
|
||
&reftitle.changelog;
|
||
<informaltable>
|
||
<tgroup cols="2">
|
||
<thead>
|
||
<row>
|
||
<entry>&Version;</entry>
|
||
<entry>&Description;</entry>
|
||
</row>
|
||
</thead>
|
||
<tbody>
|
||
<row>
|
||
<entry>8.0.0</entry>
|
||
<entry>
|
||
Функция больше не возвращает &null; в случае возникновения ошибки.
|
||
</entry>
|
||
</row>
|
||
</tbody>
|
||
</tgroup>
|
||
</informaltable>
|
||
</refsect1>
|
||
|
||
<refsect1 role="examples">
|
||
&reftitle.examples;
|
||
<example>
|
||
<title>Импорт SimpleXML в DOM с помощью функции <function>dom_import_simplexml</function></title>
|
||
<programlisting role="php">
|
||
<![CDATA[
|
||
<?php
|
||
|
||
$sxe = simplexml_load_string('<books><book><title>чепуха</title></book></books>');
|
||
|
||
if ($sxe === false) {
|
||
echo 'Ошибка при разборе документа';
|
||
exit;
|
||
}
|
||
|
||
$dom_sxe = dom_import_simplexml($sxe);
|
||
if (!$dom_sxe) {
|
||
echo 'Ошибка при преобразовании XML';
|
||
exit;
|
||
}
|
||
|
||
$dom = new DOMDocument('1.0');
|
||
$dom_sxe = $dom->importNode($dom_sxe, true);
|
||
$dom_sxe = $dom->appendChild($dom_sxe);
|
||
|
||
echo $dom->saveXML();
|
||
|
||
?>
|
||
]]>
|
||
</programlisting>
|
||
&example.outputs;
|
||
<screen>
|
||
<![CDATA[
|
||
<?xml version="1.0"?>
|
||
<books><book><title>blah</title></book></books>
|
||
]]>
|
||
</screen>
|
||
</example>
|
||
<example>
|
||
<title>Импорт SimpleXML в DOM и изменение SimpleXML через DOM</title>
|
||
<simpara>
|
||
Обработка ошибок опущена для краткости.
|
||
</simpara>
|
||
<programlisting role="php">
|
||
<![CDATA[
|
||
<?php
|
||
|
||
$sxe = simplexml_load_string('<books><book><title>blah</title></book></books>');
|
||
$elt = dom_import_simplexml($sxe);
|
||
$elt->setAttribute("foo", "bar");
|
||
echo $sxe->asXML();
|
||
|
||
?>
|
||
]]>
|
||
</programlisting>
|
||
&example.outputs;
|
||
<screen>
|
||
<![CDATA[
|
||
<?xml version="1.0"?>
|
||
<books foo="bar"><book><title>blah</title></book></books>
|
||
]]>
|
||
</screen>
|
||
</example>
|
||
</refsect1>
|
||
<refsect1 role="seealso">
|
||
&reftitle.seealso;
|
||
<para>
|
||
<simplelist>
|
||
<member><function>simplexml_import_dom</function></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
|
||
-->
|