]> git.mxchange.org Git - friendica.git/blobdiff - include/xml.php
Some more documentation
[friendica.git] / include / xml.php
index aa74cf65cf23ae2924fe77891671fd753f8ffe11..76ad88cf48571002b60d9af868c565d6b31f857e 100644 (file)
@@ -1,6 +1,10 @@
 <?php
 /**
  * @file include/xml.php
+ */
+
+
+/**
  * @brief This class contain functions to work with XML data
  *
  */
@@ -88,5 +92,40 @@ class xml {
                                self::copy($childentry, $child, $childfield);
                }
        }
+
+       /**
+        * @brief Create an XML element
+        *
+        * @param object $doc XML root
+        * @param string $element XML element name
+        * @param string $value XML value
+        * @param array $attributes array containing the attributes
+        *
+        * @return object XML element object
+        */
+       public static function create_element($doc, $element, $value = "", $attributes = array()) {
+               $element = $doc->createElement($element, xmlify($value));
+
+               foreach ($attributes AS $key => $value) {
+                       $attribute = $doc->createAttribute($key);
+                       $attribute->value = xmlify($value);
+                       $element->appendChild($attribute);
+               }
+               return $element;
+       }
+
+       /**
+        * @brief Create an XML and append it to the parent object
+        *
+        * @param object $doc XML root
+        * @param object $parent parent object
+        * @param string $element XML element name
+        * @param string $value XML value
+        * @param array $attributes array containing the attributes
+        */
+       public static function add_element($doc, $parent, $element, $value = "", $attributes = array()) {
+               $element = self::create_element($doc, $element, $value, $attributes);
+               $parent->appendChild($element);
+       }
 }
 ?>