@@ 359-384 (lines=26) @@ | ||
356 | * <p>DOMElement a new instance of class DOMElement or false |
|
357 | * if an error occured.</p> |
|
358 | */ |
|
359 | protected function changeElementName(\DOMNode $node, string $name) |
|
360 | { |
|
361 | $ownerDocument = $node->ownerDocument; |
|
362 | if (!$ownerDocument) { |
|
363 | return false; |
|
364 | } |
|
365 | ||
366 | $newNode = $ownerDocument->createElement($name); |
|
367 | ||
368 | foreach ($node->childNodes as $child) { |
|
369 | $child = $ownerDocument->importNode($child, true); |
|
370 | $newNode->appendChild($child); |
|
371 | } |
|
372 | ||
373 | foreach ($node->attributes ?? [] as $attrName => $attrNode) { |
|
374 | /** @noinspection UnusedFunctionResultInspection */ |
|
375 | $newNode->setAttribute($attrName, $attrNode); |
|
376 | } |
|
377 | ||
378 | if ($newNode->ownerDocument) { |
|
379 | /** @noinspection UnusedFunctionResultInspection */ |
|
380 | $newNode->ownerDocument->replaceChild($newNode, $node); |
|
381 | } |
|
382 | ||
383 | return $newNode; |
|
384 | } |
|
385 | ||
386 | /** |
|
387 | * Returns children of node. |
@@ 332-357 (lines=26) @@ | ||
329 | * <p>DOMElement a new instance of class DOMElement or false |
|
330 | * if an error occured.</p> |
|
331 | */ |
|
332 | protected function changeElementName(\DOMNode $node, string $name) |
|
333 | { |
|
334 | $ownerDocument = $node->ownerDocument; |
|
335 | if (!$ownerDocument) { |
|
336 | return false; |
|
337 | } |
|
338 | ||
339 | $newNode = $ownerDocument->createElement($name); |
|
340 | ||
341 | foreach ($node->childNodes as $child) { |
|
342 | $child = $ownerDocument->importNode($child, true); |
|
343 | $newNode->appendChild($child); |
|
344 | } |
|
345 | ||
346 | foreach ($node->attributes ?? [] as $attrName => $attrNode) { |
|
347 | /** @noinspection UnusedFunctionResultInspection */ |
|
348 | $newNode->setAttribute($attrName, $attrNode); |
|
349 | } |
|
350 | ||
351 | if ($newNode->ownerDocument) { |
|
352 | /** @noinspection UnusedFunctionResultInspection */ |
|
353 | $newNode->ownerDocument->replaceChild($newNode, $node); |
|
354 | } |
|
355 | ||
356 | return $newNode; |
|
357 | } |
|
358 | ||
359 | /** |
|
360 | * Returns children of node. |