change yaml format
This commit is contained in:
45
to_XML.php
Normal file
45
to_XML.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
$file = $argv[1];
|
||||
$site = basename($file, ".yaml");
|
||||
$__DIR__ = __DIR__;
|
||||
|
||||
$conf = yaml_parse_file($file);
|
||||
|
||||
$xml = new DomDocument("1.0");
|
||||
$xml->appendChild($xml->createProcessingInstruction("xml-stylesheet", "href='../results.xsl' type='text/xsl'"));
|
||||
$root = $xml->appendChild($xml->createElement("lanScanConfig"));
|
||||
$root->setAttribute("scanpath", "scans/$site.xml");
|
||||
|
||||
function appendArray($document, $node, $array) {
|
||||
foreach ($array as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
foreach ($value as $vkey => $vvalue) {
|
||||
if (is_string($vkey)) {
|
||||
if (is_array($vvalue)) {
|
||||
$child = $document->createElement($vkey);
|
||||
toXML($document, $child, $vvalue);
|
||||
} else {
|
||||
$child = $document->createElement($vkey, $vvalue);
|
||||
}
|
||||
$node->appendChild($child);
|
||||
} else {
|
||||
if (is_array($vvalue)) {
|
||||
$child = $document->createElement($key);
|
||||
appendArray($document, $child, $vvalue);
|
||||
} else {
|
||||
$child = $document->createElement($key, $vvalue);
|
||||
}
|
||||
$node->appendChild($child);
|
||||
}
|
||||
|
||||
}
|
||||
} else {
|
||||
$node->setAttribute($key, $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
appendArray($xml, $root, $conf);
|
||||
|
||||
print $xml->saveXML();
|
||||
?>
|
Reference in New Issue
Block a user