-
Notifications
You must be signed in to change notification settings - Fork 0
/
to_XML.php
47 lines (41 loc) · 1.52 KB
/
to_XML.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
$file = $argv[1];
$site = basename($file, ".yml");
$__DIR__ = __DIR__;
$conf = yaml_parse_file($file);
$xml = new DomDocument("1.0", "utf-8");
$xml->preserveWhiteSpace = false;
$xml->formatOutput = true;
$xml->appendChild($xml->createProcessingInstruction("xml-stylesheet", "href='../results.xsl' type='text/xsl'"));
$root = $xml->appendChild($xml->createElement("lanScan"));
$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();
?>