createDocumentFragment example

return self::FORMAT === $format;
    }

    public function supportsDecoding(string $format): bool
    {
        return self::FORMAT === $format;
    }

    final protected function appendXMLString(\DOMNode $node, string $val): bool
    {
        if ('' !== $val) {
            $frag = $node->ownerDocument->createDocumentFragment();
            $frag->appendXML($val);
            $node->appendChild($frag);

            return true;
        }

        return false;
    }

    final protected function appendText(\DOMNode $node, string $val): bool
    {
        
public static function escapeCdataElement(\DOMNode $node$comment_start = '//', $comment_end = '') {
    foreach ($node->childNodes as $child_node) {
      if ($child_node instanceof \DOMCdataSection) {
        $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() */
$config_node = $xml_nodes->item( 0 );
                    $config_node->appendChild( $system_web_server_node );
                } else {
                    $config_node = $doc->createElement( 'configuration' );
                    $doc->appendChild( $config_node );
                    $config_node->appendChild( $system_web_server_node );
                }
            }
        }
    }

    $rule_fragment = $doc->createDocumentFragment();
    $rule_fragment->appendXML( $rewrite_rule );
    $rules_node->appendChild( $rule_fragment );

    $doc->encoding     = 'UTF-8';
    $doc->formatOutput = true;
    saveDomDocument( $doc$filename );

    return true;
}

/** * Saves the XML document into a file. * * @since 2.8.0 * * @param DOMDocument $doc * @param string $filename */
return self::FORMAT === $format;
    }

    public function supportsDecoding(string $format): bool
    {
        return self::FORMAT === $format;
    }

    final protected function appendXMLString(\DOMNode $node, string $val): bool
    {
        if ('' !== $val) {
            $frag = $node->ownerDocument->createDocumentFragment();
            $frag->appendXML($val);
            $node->appendChild($frag);

            return true;
        }

        return false;
    }

    final protected function appendText(\DOMNode $node, string $val): bool
    {
        
if (isset($this->options[self::OPT_IMPLICIT_NS])) {
            $implicitNS = $this->options[self::OPT_IMPLICIT_NS];
        } elseif (isset($this->options['implicitNamespaces'])) {
            $implicitNS = $this->options['implicitNamespaces'];
        }

        // Fill $nsStack with the defalut HTML5 namespaces, plus the "implicitNamespaces" array taken form $options         array_unshift($this->nsStack, $implicitNS + array('' => self::NAMESPACE_HTML) + $this->implicitNamespaces);

        if ($isFragment) {
            $this->insertMode = static::IM_IN_BODY;
            $this->frag = $this->doc->createDocumentFragment();
            $this->current = $this->frag;
        }
    }

    /** * Get the document. */
    public function document()
    {
        return $this->doc;
    }

    
return '';
        }
    }

    protected function strip_tag($tag$document$xpath$type)
    {
        $elements = $xpath->query('body//' . $tag);
        if ($this->encode_instead_of_strip)
        {
            foreach ($elements as $element)
            {
                $fragment = $document->createDocumentFragment();

                // For elements which aren't script or style, include the tag itself                 if (!in_array($tag, array('script', 'style')))
                {
                    $text = '<' . $tag;
                    if ($element->hasAttributes())
                    {
                        $attrs = array();
                        foreach ($element->attributes as $name => $attr)
                        {
                            $value = $attr->value;

                            
Home | Imprint | This part of the site doesn't use cookies.