*
* Created on Sep 19, 2006
*
- * Copyright © 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
+ * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
/**
* This method takes an array and converts it to XML.
+ *
* There are several noteworthy cases:
*
- * If array contains a key '_element', then the code assumes that ALL other keys are not important and replaces them with the value['_element'].
- * Example: name='root', value = array( '_element'=>'page', 'x', 'y', 'z') creates <root> <page>x</page> <page>y</page> <page>z</page> </root>
+ * If array contains a key '_element', then the code assumes that ALL
+ * other keys are not important and replaces them with the
+ * value['_element'].
+ *
+ * @par Example:
+ * @verbatim
+ * name='root', value = array( '_element'=>'page', 'x', 'y', 'z')
+ * @endverbatim
+ * creates:
+ * @verbatim
+ * <root> <page>x</page> <page>y</page> <page>z</page> </root>
+ * @endverbatim
+ *
+ * If any of the array's element key is '*', then the code treats all
+ * other key->value pairs as attributes, and the value['*'] as the
+ * element's content.
+ *
+ * @par Example:
+ * @verbatim
+ * name='root', value = array( '*'=>'text', 'lang'=>'en', 'id'=>10)
+ * @endverbatim
+ * creates:
+ * @verbatim
+ * <root lang='en' id='10'>text</root>
+ * @endverbatim
*
- * If any of the array's element key is '*', then the code treats all other key->value pairs as attributes, and the value['*'] as the element's content.
- * Example: name='root', value = array( '*'=>'text', 'lang'=>'en', 'id'=>10) creates <root lang='en' id='10'>text</root>
+ * Finally neither key is found, all keys become element names, and values
+ * become element content.
*
- * If neither key is found, all keys become element names, and values become element content.
- * The method is recursive, so the same rules apply to any sub-arrays.
+ * @note The method is recursive, so the same rules apply to any
+ * sub-arrays.
*
* @param $elemName
* @param $elemValue
// ignore
break;
default:
- $retval .= $indstr . Xml::element( $elemName, null, $elemValue );
+ // to make sure null value doesn't produce unclosed element,
+ // which is what Xml::element( $elemName, null, null ) returns
+ if ( $elemValue === null ) {
+ $retval .= $indstr . Xml::element( $elemName );
+ } else {
+ $retval .= $indstr . Xml::element( $elemName, null, $elemValue );
+ }
break;
}
return $retval;
public function getDescription() {
return 'Output data in XML format' . parent::getDescription();
}
-
- public function getVersion() {
- return __CLASS__ . ': $Id$';
- }
}