read/write xml file in php, task
This commit is contained in:
36
Zweites Jahr/XML/readXmlDocument.php
Normal file
36
Zweites Jahr/XML/readXmlDocument.php
Normal 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>";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user