[ create a new paste ] login | about

Link: http://codepad.org/RyhQSgcm    [ raw code | output | fork ]

PHP, pasted on Jun 6:
<?php

$data = array(
	"Engine.Renderer" => array(
		"driver" => "EN_SOFTWARE",
		"plugin_api_file" => "\${SYSTEM_PATH}/data/plugin_api.nut",
	),
	"Engine.Network" => array(
		"localport" => "8097",
	),
	"Engine.Client" => array(
		"version" => "2.03",
		"auto_updates" => "false", 
	),
);

header("Content-Type: text/plain");

$doc = new SimpleXMLElement("<root></root>");
foreach($data as $sec => $items)
{
	$child = $doc->addChild("section");
	$child->addAttribute("identifier", $sec);
	foreach($items as $item => $itemdata)
	{
		$itemnode = $child->addChild("item", $itemdata);
		$itemnode->addAttribute("name", $item);
	}
}

$domdocument = new DOMDocument('1.0');
$domdocument->formatOutput = true;
$domdocument->preserveWhiteSpace = false;
$domnode = dom_import_simplexml($doc);
$domnode = $domdocument->importNode($domnode, true);
$domnode = $domdocument->appendChild($domnode);

echo $domdocument->saveXML(); 


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?xml version="1.0"?>
<root>
  <section identifier="Engine.Renderer">
    <item name="driver">EN_SOFTWARE</item>
    <item name="plugin_api_file">${SYSTEM_PATH}/data/plugin_api.nut</item>
  </section>
  <section identifier="Engine.Network">
    <item name="localport">8097</item>
  </section>
  <section identifier="Engine.Client">
    <item name="version">2.03</item>
    <item name="auto_updates">false</item>
  </section>
</root>


Create a new paste based on this one


Comments: