X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiFormatXml.php;h=8dbeae497bd28e737d33545164dd7e4e7a2dc5c2;hb=a36db2e887aa6bc1dec9a52bb6003689d67daf01;hp=ef2c54f59e9f226410d27d99360a88594e352a34;hpb=fccc2f1b8b1dc6d789f25b1dbfbfd6b04b1036d5;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiFormatXml.php b/includes/api/ApiFormatXml.php index ef2c54f59e..8dbeae497b 100644 --- a/includes/api/ApiFormatXml.php +++ b/includes/api/ApiFormatXml.php @@ -4,7 +4,7 @@ * * Created on Sep 19, 2006 * - * Copyright © 2006 Yuri Astrakhan @gmail.com + * Copyright © 2006 Yuri Astrakhan "@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 @@ -83,16 +83,40 @@ class ApiFormatXml extends ApiFormatBase { /** * 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 x y z + * 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 + * x y z + * @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 + * text + * @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 text + * 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 @@ -181,7 +205,13 @@ class ApiFormatXml extends ApiFormatBase { // 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; @@ -224,8 +254,4 @@ class ApiFormatXml extends ApiFormatBase { public function getDescription() { return 'Output data in XML format' . parent::getDescription(); } - - public function getVersion() { - return __CLASS__ . ': $Id$'; - } }