-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOgerXML.class.php
More file actions
77 lines (49 loc) · 1.33 KB
/
OgerXML.class.php
File metadata and controls
77 lines (49 loc) · 1.33 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
71
72
73
74
75
76
77
<?php
/*
#LICENSE BEGIN
**********************************************************************
* OgerArch - Archaeological Database is released under the GNU General Public License (GPL) <http://www.gnu.org/licenses>
* Copyright (C) Gerhard Öttl <gerhard.oettl@ogersoft.at>
**********************************************************************
#LICENSE END
*/
/**
* Extended XML handling
*/
class OgerXML {
/*
* convert array to xml
*/
public static function arrayToXml($rootName, $array) {
$writer = new XMLWriter();
$writer->openMemory();
$writer->setIndent(true);
$writer->setIndentString(' ');
$writer->startDocument('1.0', 'UTF-8');
$writer->startElement($rootName);
self::arrayToXmlWorker($writer, $array);
$writer->endElement();
$writer->endDocument();
return $writer->outputMemory();
} // eo convert array to xml
/*
* convert an single array item to xml
*/
private static function arrayToXmlWorker($writer, $array) {
foreach($array as $key => $value) {
$tagName = $key;
if (is_numeric($key)) {
$tagName = "__ITEM__";
}
$writer->startElement($tagName);
if (is_array($value)) {
self::arrayToXmlWorker($writer, $value);
}
else {
$writer->text($value);
}
$writer->fullEndElement();
} // eo array
} // eo array to xml worker
} // eo class
?>