]> git.mxchange.org Git - friendica.git/blob - include/xml.php
Some code cleaning, changes to the xml generation
[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, $remove_header = false) {
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
18                                 $xml_text = $dom->saveXML();
19
20                                 if ($remove_header)
21                                         $xml_text = trim(substr($xml_text, 21));
22
23                                 return $xml_text;
24                         }
25                 }
26
27                 foreach($array as $key => $value) {
28                         if (!is_array($value) AND !is_numeric($key))
29                                 $xml->addChild($key, xmlify($value));
30                         elseif (is_array($value))
31                                 self::from_array($value, $xml->addChild($key));
32                 }
33         }
34
35         function copy(&$source, &$target, $elementname) {
36                 if (count($source->children()) == 0)
37                         $target->addChild($elementname, $source);
38                 else {
39                         $child = $target->addChild($elementname);
40                         foreach ($source->children() AS $childfield => $childentry)
41                                 self::copy($childentry, $child, $childfield);
42                 }
43         }
44 }
45 ?>