appendXML example



    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
    {
        $nodeText = $node->ownerDocument->createTextNode($val);
        


    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
    {
        $nodeText = $node->ownerDocument->createTextNode($val);
        
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->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 */
Home | Imprint | This part of the site doesn't use cookies.