2
0

read/write xml file in php, task

This commit is contained in:
cwikladaniel
2025-12-11 11:35:44 +01:00
parent d26d5ea4a7
commit a1040bd5db
11 changed files with 298 additions and 22 deletions

View File

@@ -0,0 +1,36 @@
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
echo "<h1>XML Ausgabe</h1>";
// load xml file
$xmlDoc = new DOMDocument();
$xmlDoc->load("personen.xml");
echo "<h2>Einfach</h1>";
// simple output
echo $xmlDoc->saveXML();
echo "<hr>";
echo "<h2>Gesamte Knoten</h1>";
// output of individual nodes
$benutzer=$xmlDoc->getElementsByTagName("benutzer");
foreach($benutzer as $benutzerDaten){
echo "<strong>Person: </strong>".$benutzerDaten->textContent."<br>";
}
echo "<hr>";
echo "<h2>Element eines Knotens</h1>";
// output of an node's element
foreach($benutzer as $benutzerDaten){
foreach($benutzerDaten->childNodes as $element){
if($element->nodeName == "benutzername"){
echo "<strong>Person: </strong>".$element->textContent."<br>";
}
}
}