PHP.mk документација

DOMDocument::importNode

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

domdocument.importnode.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека domdocument.importnode.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
DOMDocument::importNode

Референца за `domdocument.importnode.php` со подобрена типографија и навигација.

domdocument.importnode.php

DOMDocument::importNode

класата mysqli_driver

DOMDocument::importNodeУвоз на јазол во тековниот документ

= NULL

public DOMDocument::importNode(DOMNode $node, bool $deep = false): DOMNode|false

Оваа функција враќа копија на јазолот за увоз и го поврзува со тековниот документ.

Параметри

node

Јазолот за увоз.

deep

Ако е поставено на true, овој метод рекурзивно ќе го увезе поддрвото под node.

Забелешка:

За копирање на атрибутите на јазлите deep мора да биде поставено на true

Вратени вредности

Копираниот јазол или false, ако не може да се копира.

Errors/Exceptions

DOMException се фрла ако јазолот не може да се увезе.

Примери

Пример #1 Го префрла елементот hello од првиот документ во вториот. example

Копирање јазли помеѓу документи.

<?php

$orgdoc
= new DOMDocument;
$orgdoc->loadXML("<root><element><child>text in child</child></element></root>");

// The node we want to import to a new document
$node = $orgdoc->getElementsByTagName("element")->item(0);


// Create a new document
$newdoc = new DOMDocument;
$newdoc->formatOutput = true;

// Add some markup
$newdoc->loadXML("<root><someelement>text in some element</someelement></root>");

echo
"The 'new document' before copying nodes into it:\n";
echo
$newdoc->saveXML();

// Import the node, and all its children, to the document
$node = $newdoc->importNode($node, true);
// And then append it to the "<root>" node
$newdoc->documentElement->appendChild($node);

echo
"\nThe 'new document' after copying the nodes into it:\n";
echo
$newdoc->saveXML();
?>

Пример #1 Пример што покажува затворачка ознака што го опфаќа последниот нов ред

The 'new document' before copying nodes into it:
<?xml version="1.0"?>
<root>
  <someelement>text in some element</someelement>
</root>

The 'new document' after copying the nodes into it:
<?xml version="1.0"?>
<root>
  <someelement>text in some element</someelement>
  <element>
    <child>text in child</child>
  </element>
</root>

Белешки од корисници 2 забелешки

c точка 1 на smithies точка org
пред 16 години
Assume that $source and $dest are instances of DOMDocument. Assume that $sourcedoc contains an element with ID 'sourceID' and that $destdoc contains an element with ID 'destID'. Assume that we have already set up source and destination element variables thus:

<?php
 $src = $sourcedoc->getElementById('sourceID');
 $dst = $destdoc->getElementById('destID');
?>

Finally, assume that $sel has more than one child node.

In order to import the child elements of $src as children of $dst, you might do something like this:

<?php
$src = $dest->importNode($src, TRUE);

foreach ($src->childNodes as $el) $dst->appendChild($el);
?>

But this does not work. foreach gets confused, because (as noted below) appending an imported element to another existing element in the same document causes it to be removed from its current parent element.

Therefore, the following technique should be used:

<?php
foreach ($src->childNodes as $el) $dst->appendChild($destdoc->importNode($el, TRUE));
?>
Fitopaldi
20 години пред
importNode returns a copy of the node to import and associates it with the current document, but not import the node to the current DOMDocument. Use appendChild for import the copy of the node to current DOMDocument.

<?
 $domNode = $dom->importNode($aDomNode, true);
 $currentDomDocument->appendChild($domNode);
?>
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.