X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fxml.php;h=76ad88cf48571002b60d9af868c565d6b31f857e;hb=08fb662b4a7b9c94a5882b0c6f47ed463dfb0ba2;hp=c74c23c473ce3254a717e155e8c6a707958dd58e;hpb=be5267edda51eb4b523324c001bcf90ca60e1fa5;p=friendica.git diff --git a/include/xml.php b/include/xml.php index c74c23c473..76ad88cf48 100644 --- a/include/xml.php +++ b/include/xml.php @@ -1,10 +1,26 @@ $value) { @@ -60,7 +76,14 @@ class xml { } } - function copy(&$source, &$target, $elementname) { + /** + * @brief Copies an XML object + * + * @param object $source The XML source + * @param object $target The XML target + * @param string $elementname Name of the XML element of the target + */ + public static function copy(&$source, &$target, $elementname) { if (count($source->children()) == 0) $target->addChild($elementname, xmlify($source)); else { @@ -69,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); + } } ?>