44 $this->mIncludeNamespace = $params[
'includexmlnamespace'];
45 $this->mXslt = $params[
'xslt'];
47 $this->
printText(
'<?xml version="1.0"?>' );
48 if ( $this->mXslt !==
null ) {
53 if ( $this->mIncludeNamespace && $result->getResultData(
'xmlns' ) ===
null ) {
58 $result->addValue(
null,
'xmlns', self::$namespace, ApiResult::NO_SIZE_CHECK );
60 $data = $result->getResultData(
null, [
61 'Custom' =>
static function ( &$data, &$metadata ) {
62 if ( isset( $metadata[ApiResult::META_TYPE] ) ) {
64 switch ( $metadata[ApiResult::META_TYPE] ) {
66 $metadata[ApiResult::META_TYPE] =
'assoc';
71 'BC' => [
'nobool',
'no*',
'nosub' ],
72 'Types' => [
'ArmorKVP' =>
'_name' ],
76 static::recXmlPrint( $this->mRootElemName,
92 public static function recXmlPrint( $name, $value, $indent, $attributes = [] ) {
94 if ( $indent !==
null ) {
95 if ( $name !==
null ) {
98 $indstr =
"\n" . str_repeat(
' ', $indent );
103 if ( is_object( $value ) ) {
104 $value = (array)$value;
106 if ( is_array( $value ) ) {
107 $contentKey = $value[ApiResult::META_CONTENT] ??
'*';
108 $subelementKeys = $value[ApiResult::META_SUBELEMENTS] ?? [];
109 if ( isset( $value[ApiResult::META_BC_SUBELEMENTS] ) ) {
110 $subelementKeys = array_merge(
111 $subelementKeys, $value[ApiResult::META_BC_SUBELEMENTS]
114 $preserveKeys = $value[ApiResult::META_PRESERVE_KEYS] ?? [];
115 $indexedTagName = isset( $value[ApiResult::META_INDEXED_TAG_NAME] )
116 ?
self::mangleName( $value[ApiResult::META_INDEXED_TAG_NAME], $preserveKeys )
118 $bcBools = $value[ApiResult::META_BC_BOOLS] ?? [];
119 $indexSubelements = isset( $value[ApiResult::META_TYPE] )
120 ? $value[ApiResult::META_TYPE] !==
'array'
125 $indexedSubelements = [];
126 foreach ( $value as $k => $v ) {
127 if ( ApiResult::isMetadataKey( $k ) && !in_array( $k, $preserveKeys,
true ) ) {
132 if ( is_bool( $v ) && !in_array( $k, $bcBools,
true ) ) {
133 $v = $v ?
'true' :
'false';
136 if ( $name !==
null && $k === $contentKey ) {
138 } elseif ( is_int( $k ) ) {
139 $indexedSubelements[$k] = $v;
140 } elseif ( is_array( $v ) || is_object( $v ) ) {
142 } elseif ( in_array( $k, $subelementKeys,
true ) || $name ===
null ) {
145 ApiResult::META_CONTENT =>
'content',
146 ApiResult::META_TYPE =>
'assoc',
148 } elseif ( is_bool( $oldv ) ) {
152 } elseif ( $v !==
null ) {
158 if ( $subelements || $indexedSubelements ) {
161 ApiResult::META_CONTENT =>
'content',
162 ApiResult::META_TYPE =>
'assoc',
165 } elseif ( is_scalar(
$content ) ) {
168 $attributes += [
'xml:space' =>
'preserve' ];
174 $retval .= $indstr . Xml::element( $name, $attributes,
$content );
176 if ( $name !==
null ) {
177 $retval .= $indstr . Xml::element( $name, $attributes,
null );
179 $retval .= static::recXmlPrint(
null,
$content, $indent );
180 if ( $name !==
null ) {
181 $retval .= $indstr . Xml::closeElement( $name );
184 } elseif ( !$indexedSubelements && !$subelements ) {
185 if ( $name !==
null ) {
186 $retval .= $indstr . Xml::element( $name, $attributes );
189 if ( $name !==
null ) {
190 $retval .= $indstr . Xml::element( $name, $attributes,
null );
192 foreach ( $subelements as $k => $v ) {
193 $retval .= static::recXmlPrint( $k, $v, $indent );
195 foreach ( $indexedSubelements as $k => $v ) {
196 $retval .= static::recXmlPrint( $indexedTagName, $v, $indent,
197 $indexSubelements ? [
'_idx' => $k ] : []
200 if ( $name !==
null ) {
201 $retval .= $indstr . Xml::closeElement( $name );
207 if ( $value ===
null ) {
208 $retval .= $indstr . Xml::element( $name, $attributes );
210 $retval .= $indstr . Xml::element( $name, $attributes, $value );