DOMDocument::saveXML

(PHP 5, PHP 7, PHP 8)

DOMDocument::saveXML Dumps the internal XML tree back into a string

Beschreibung

public DOMDocument::saveXML(?DOMNode $node = null, int $options = 0): string|false

Creates an XML document from the DOM representation. This function is usually called after building a new dom document from scratch as in the example below.

Parameter-Liste

node

Use this parameter to output only a specific node without XML declaration rather than the entire document.

options

Additional Options. Currently only LIBXML_NOEMPTYTAG is supported.

Rückgabewerte

Returns the XML, or false if an error occurred.

Fehler/Exceptions

DOM_WRONG_DOCUMENT_ERR

Raised if node is from another document.

Beispiele

Beispiel #1 Saving a DOM tree into a string

<?php

$doc 
= new DOMDocument('1.0');
// we want a nice output
$doc->formatOutput true;

$root $doc->createElement('book');
$root $doc->appendChild($root);

$title $doc->createElement('title');
$title $root->appendChild($title);

$text $doc->createTextNode('This is the title');
$text $title->appendChild($text);

echo 
"Saving all the document:\n";
echo 
$doc->saveXML() . "\n";

echo 
"Saving only the title part:\n";
echo 
$doc->saveXML($title);

?>

Das oben gezeigte Beispiel erzeugt folgende Ausgabe:

Saving all the document:
<?xml version="1.0"?>
<book>
  <title>This is the title</title>
</book>

Saving only the title part:
<title>This is the title</title>

Siehe auch

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

Was genau bedeutet "Vibe Coding"? Ein tiefgehender Blick für Entwickler

In der Welt der Softwareentwicklung gibt es unzählige Wege, wie man an ein Projekt herangeht. Manche schwören auf strikte Planung, andere auf bewährte Algorithmen und wieder andere lassen sich von etwas ganz anderem leiten: ihrem Gefühl. ...

admin

Autor : admin
Kategorie: Software & Web-Development

PHP cURL-Tutorial: Verwendung von cURL zum Durchführen von HTTP-Anfragen

cURL ist eine leistungsstarke PHP-Erweiterung, die es Ihnen ermöglicht, mit verschiedenen Servern über verschiedene Protokolle wie HTTP, HTTPS, FTP und mehr zu kommunizieren. ...

TheMax

Autor : TheMax
Kategorie: PHP-Tutorials

Midjourney Tutorial - Anleitung für Anfänger

Über Midjourney, dem Tool zur Erstellung digitaler Bilder mithilfe von künstlicher Intelligenz, gibt es ein informatives Video mit dem Titel "Midjourney Tutorial auf Deutsch - Anleitung für Anfänger" ...

Mike94

Autor : Mike94
Kategorie: KI Tutorials

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

Suche nach Best Practices zur Leistungsoptimierung von PHP-Skripten!!

Hallo zusammen, Ich habe an einem Projekt mit einigen komplexen PHP-Skripten gearbeitet und mir sind Leistungsprobleme aufgefallen, insbesondere ...

Geschrieben von Isabellay am 30.05.2025 09:41:02
Forum: PHP Developer Forum
Variable Gültigkeit in Blöcken

That's a sharp observation! You're absolutely right – the core issue isn't where the console.log() is placed, but when it executes relative to w ...

Geschrieben von Bendomenech68 am 30.05.2025 09:28:17
Forum: HTML, JavaScript, AJAX, jQuery, CSS, Bootstrap, LESS
Eingabe in einer Datenbank

Schön, dass du dich mit SQL und PHP beschäftigst. Wenn die Ausgabe aus der Datenbank schon funktioniert, aber die Eingabe nicht, kann es tatsäc ...

Geschrieben von karina am 30.05.2025 09:14:22
Forum: SQL / Datenbanken
Mailversand aus Kontaktformular mit Datei Upload / Technischer Ablauf php / EU-Recht

Regarding the technical process: For most contact forms with file upload, the file is first temporarily stored on the server so it can be attached ...

Geschrieben von lyraellington12 am 30.05.2025 09:08:05
Forum: PHP Developer Forum