XML; $sammlung = new SimpleXMLElement($basis_xml); // Opel $fahrzeug = $sammlung->addChild("fahrzeug"); $fahrzeug->addChild("marke", "Opel"); $fahrzeug->addChild("typ", "Astra"); $motordaten = $fahrzeug->addChild("motordaten"); $motordaten->addChild("leistung", "70 kW"); $motordaten->addChild("hubraum", "1600 ccm"); $fahrzeug->addChild("gewicht", "1200 kg"); $fahrzeug->addChild("reifen", "155 R 14"); $fahrzeug->addChild("reifen", "165 H 14"); // Ford $fahrzeug = $sammlung->addChild("fahrzeug"); $fahrzeug->addChild("marke", "Ford"); $fahrzeug->addChild("typ", "Focus"); $motordaten = $fahrzeug->addChild("motordaten"); $motordaten->addChild("leistung", "80 kW"); $motordaten->addChild("hubraum", "1700 ccm"); $fahrzeug->addChild("gewicht", "1100 kg"); $fahrzeug->addChild("reifen", "185-60 R 13"); $fahrzeug->addChild("reifen", "205-70 R 13"); echo $sammlung->asXML(); // Variante DOM require_once 'XmlExtractor.php'; require_once 'XmlFormatter.php'; $xmlFormatter = new XmlFormatter(); $xmlFormatter->initResult(); // Top-Knoten $xmlFormatter->formatElement(OutputFormatter::FC_BEG, "sammlung"); // Opel $xmlFormatter->formatElement(OutputFormatter::FC_BEG, "fahrzeug"); $xmlFormatter->formatElement(OutputFormatter::FC_SGL, "marke", "Opel"); $xmlFormatter->formatElement(OutputFormatter::FC_SGL, "typ", "Astra"); $xmlFormatter->formatElement(OutputFormatter::FC_BEG, "motordaten"); $xmlFormatter->formatElement(OutputFormatter::FC_SGL, "leistung", "70 kW"); $xmlFormatter->formatElement(OutputFormatter::FC_SGL, "hubraum", "1600 ccm"); $xmlFormatter->formatElement(OutputFormatter::FC_END); // Zurück zu $xmlFormatter->formatElement(OutputFormatter::FC_SGL, "gewicht", "1200 kg"); $xmlFormatter->formatElement(OutputFormatter::FC_SGL, "reifen", "155 R 14"); $xmlFormatter->formatElement(OutputFormatter::FC_SGL, "reifen", "165 H 14"); $xmlFormatter->formatElement(OutputFormatter::FC_END); // Zurück zu // Ford $xmlFormatter->formatElement(OutputFormatter::FC_BEG, "fahrzeug"); $xmlFormatter->formatElement(OutputFormatter::FC_SGL, "marke", "Ford"); $xmlFormatter->formatElement(OutputFormatter::FC_SGL, "typ", "Focus"); $xmlFormatter->formatElement(OutputFormatter::FC_BEG, "motordaten"); $xmlFormatter->formatElement(OutputFormatter::FC_SGL, "leistung", "80 kW"); $xmlFormatter->formatElement(OutputFormatter::FC_SGL, "hubraum", "1700 ccm"); $xmlFormatter->formatElement(OutputFormatter::FC_END); // Zurück zu $xmlFormatter->formatElement(OutputFormatter::FC_SGL, "gewicht", "1100 kg"); $xmlFormatter->formatElement(OutputFormatter::FC_SGL, "reifen", "185-60 R 13"); $xmlFormatter->formatElement(OutputFormatter::FC_SGL, "reifen", "205-70 R 13"); $xml = $xmlFormatter->printIt(); echo $xml; ?>