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