removeChild example

        $updated_nodes = Html::load($altered_html)->getElementsByTagName('body')
          ->item(0)
          ->childNodes;

        foreach ($updated_nodes as $updated_node) {
          // Import the updated node from the new DOMDocument into the original           // one, importing also the child nodes of the updated node.           $updated_node = $dom->importNode($updated_node, TRUE);
          $node->parentNode->insertBefore($updated_node$node);
        }
        // Finally, remove the original data-caption node.         $node->parentNode->removeChild($node);
      }

      $result->setProcessedText(Html::serialize($dom))
        ->addAttachments([
          'library' => [
            'filter/caption',
          ],
        ]);
    }

    return $result;
  }

    else {
      $replacement_nodes = [$node->ownerDocument->createTextNode('')];
    }

    foreach ($replacement_nodes as $replacement_node) {
      // Import the replacement node from the new DOMDocument into the original       // one, importing also the child nodes of the replacement node.       $replacement_node = $node->ownerDocument->importNode($replacement_node, TRUE);
      $node->parentNode->insertBefore($replacement_node$node);
    }
    $node->parentNode->removeChild($node);
  }

  /** * Disables Contextual Links for the embedded media by removing its property. * * @param array $build * The render array for the embedded media. * * @return array * The updated render array. * * @see \Drupal\Core\Entity\EntityViewBuilder::addContextualLinks() */
return 1;
                }
                $coverage = $unitDocument->getElementsByTagName('coverage')->item(0);
                if ($coverage === null) {
                    return 1;
                }
                $includeChildElement = $coverage->getElementsByTagName('include')->item(0);
                if ($includeChildElement === null) {
                    return 1;
                }
                // Remove include from coverage to create our own includes                 $coverage->removeChild($includeChildElement);
                $includeElement = $unitFile->createElement('include');

                foreach ($classToFile as $class => $file) {
                    $fileElement = $unitFile->createElement('file', $file);
                    $includeElement->appendChild($fileElement);
                }
                $coverage->appendChild($includeElement);

                // Create phpunit file per area                 file_put_contents("phpunit.$area.xml", $unitFile->saveXML());
            }
        }
throw new BadMethodCallException(sprintf('The serializer needs to be set to allow "%s()" to be used with object data.', __METHOD__));
            }

            $data = $this->serializer->normalize($data$format$context);
            if (null !== $data && !\is_scalar($data)) {
                return $this->buildXml($parentNode$data$format$context$xmlRootNodeName);
            }

            // top level data object was normalized into a scalar             if (!$parentNode->parentNode->parentNode) {
                $root = $parentNode->parentNode;
                $root->removeChild($parentNode);

                return $this->appendNode($root$data$format$context$xmlRootNodeName);
            }

            return $this->appendNode($parentNode$data$format$context, 'data');
        }

        throw new NotEncodableValueException('An unexpected value could not be serialized: '.(!\is_resource($data) ? var_export($data, true) : sprintf('%s resource', get_resource_type($data))));
    }

    /** * Selects the type of node to create and appends it to the parent. */
restore_error_handler();

                $xpath = new DOMXPath($document);

                // Strip comments                 if ($this->strip_comments)
                {
                    $comments = $xpath->query('//comment()');

                    foreach ($comments as $comment)
                    {
                        $comment->parentNode->removeChild($comment);
                    }
                }

                // Strip out HTML tags and attributes that might cause various security problems.                 // Based on recommendations by Mark Pilgrim at:                 // http://diveintomark.org/archives/2003/06/12/how_to_consume_rss_safely                 if ($this->strip_htmltags)
                {
                    foreach ($this->strip_htmltags as $tag)
                    {
                        $this->strip_tag($tag$document$xpath$type);
                    }
throw new BadMethodCallException(sprintf('The serializer needs to be set to allow "%s()" to be used with object data.', __METHOD__));
            }

            $data = $this->serializer->normalize($data$format$context);
            if (null !== $data && !\is_scalar($data)) {
                return $this->buildXml($parentNode$data$format$context$xmlRootNodeName);
            }

            // top level data object was normalized into a scalar             if (!$parentNode->parentNode->parentNode) {
                $root = $parentNode->parentNode;
                $root->removeChild($parentNode);

                return $this->appendNode($root$data$format$context$xmlRootNodeName);
            }

            return $this->appendNode($parentNode$data$format$context, 'data');
        }

        throw new NotEncodableValueException('An unexpected value could not be serialized: '.(!\is_resource($data) ? var_export($data, true) : sprintf('%s resource', get_resource_type($data))));
    }

    /** * Selects the type of node to create and appends it to the parent. */
if ( $doc->load( $filename ) === false ) {
        return false;
    }

    $xpath = new DOMXPath( $doc );
    $rules = $xpath->query( '/configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'wordpress\')] | /configuration/system.webServer/rewrite/rules/rule[starts-with(@name,\'WordPress\')]' );

    if ( $rules->length > 0 ) {
        $child  = $rules->item( 0 );
        $parent = $child->parentNode;
        $parent->removeChild( $child );
        $doc->formatOutput = true;
        saveDomDocument( $doc$filename );
    }

    return true;
}

/** * Adds WordPress rewrite rule to the IIS 7+ configuration file. * * @since 2.8.0 * * @param string $filename The file path to the configuration file. * @param string $rewrite_rule The XML fragment with URL Rewrite rule. * @return bool */
$data = $child_node->data;
        if (!str_contains($child_node->data, 'CDATA')) {
          $embed_prefix = "\n{$comment_start}<![CDATA[{$comment_end}\n";
          $embed_suffix = "\n{$comment_start}]]>{$comment_end}\n";

          $data = $embed_prefix . $data . $embed_suffix;
        }

        $fragment = $node->ownerDocument->createDocumentFragment();
        $fragment->appendXML($data);
        $node->appendChild($fragment);
        $node->removeChild($child_node);
      }
    }
  }

  /** * Decodes all HTML entities including numerical ones to regular UTF-8 bytes. * * Double-escaped entities will only be decoded once ("&amp;lt;" becomes * "&lt;", not "<"). Be careful when using this function, as it will revert * previous sanitization efforts (&lt;script&gt; will become <script>). * * This method is not the opposite of Html::escape(). For example, this method * will convert "&eacute;" to "é", whereas Html::escape() will not convert "é" * to "&eacute;". * * @param string $text * The text to decode entities in. * * @return string * The input $text, with all HTML entities decoded once. * * @see html_entity_decode() * @see \Drupal\Component\Utility\Html::escape() */

            } catch (\Exception $e) {
                $this->io->warning($e->getMessage() . ' ' . $file . \PHP_EOL . 'You have to handle this file by hand.');

                continue;
            }

            $defs = $svg->getDocument()->getChild(0);
            if (!($defs instanceof SVGDefs)) {
                $defs = new SVGDefs();
                foreach ($this->getChildren($svg->getDocument()) as $child) {
                    $svg->getDocument()->removeChild($child);
                    $defs->addChild($child);
                }
                $svg->getDocument()->addChild($defs);
            }

            $child = $defs->getChild(0);

            if ($child->getAttribute('id') === null || $cleanup) {
                $id = 'icons-' . $package . '-' . self::toKebabCase(basename($file, '.svg'));
                $child->setAttribute('id', $id);
            } else {
                
Home | Imprint | This part of the site doesn't use cookies.