]> git.mxchange.org Git - friendica.git/blob - include/xml.php
e46f53acc05066967e919908dc1a7e5a7437da85
[friendica.git] / include / xml.php
1 <?php
2 /**
3  * @brief This class contain functions to work with XML data
4  *
5  */
6 class xml {
7         function from_array($array, &$xml) {
8
9                 if (!is_object($xml)) {
10                         foreach($array as $key => $value) {
11                                 $root = new SimpleXMLElement("<".$key."/>");
12                                 self::from_array($value, $root);
13
14                                 $dom = dom_import_simplexml($root)->ownerDocument;
15                                 $dom->formatOutput = true;
16                                 $xml = $dom;
17                                 return $dom->saveXML();
18                         }
19                 }
20
21                 foreach($array as $key => $value) {
22                         if (!is_array($value) AND !is_numeric($key))
23                                 $xml->addChild($key, $value);
24                         elseif (is_array($value))
25                                 self::from_array($value, $xml->addChild($key));
26                 }
27         }
28
29         function copy(&$source, &$target, $elementname) {
30                 if (count($source->children()) == 0)
31                         $target->addChild($elementname, $source);
32                 else {
33                         $child = $target->addChild($elementname);
34                         foreach ($source->children() AS $childfield => $childentry)
35                                 self::copy($childentry, $child, $childfield);
36                 }
37         }
38 }
39 ?>