-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
70 lines (36 loc) · 1.13 KB
/
functions.php
File metadata and controls
70 lines (36 loc) · 1.13 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
function array2xml(array $array, SimpleXMLElement &$xml): void {
foreach ($array as $k => $d) {
if ($k === "@attributes") {
foreach($d as $key => $value) {
preg_match("/^xml:.+$/i", $key, $namespace);
$xml->addAttribute($key, $value, empty($namespace) ? null : "http://www.w3.org/XML/1998/namespace");
}
continue;
}
if ($k === "@values") {
$parent = $xml->xpath("..")[0];
foreach ($d as $v) {
$child = $parent->addChild($xml->getName());
array2xml($v, $child);
}
unset($xml[0]);
continue;
}
if ($k === 0) {
$xml[0] = $d;
continue;
}
${$k} = $xml->addChild($k);
if (is_array($d)) {
array2xml($d, ${$k});
} else {
${$k}[0] = $d;
}
}
}
function xml4output(SimpleXMLElement $xml, $dom = new DOMDocument("1.0", "UTF-8")): string {
$dom->formatOutput = true;
$dom->loadXML($xml->asXML());
return $dom->saveXML();
}