46 $this->mIncludeNamespace = $params[
'includexmlnamespace'];
47 $this->mXslt = $params[
'xslt'];
49 $this->
printText(
'<?xml version="1.0"?>' );
50 if ( $this->mXslt !==
null ) {
55 if ( $this->mIncludeNamespace && $result->getResultData(
'xmlns' ) ===
null ) {
60 $result->addValue(
null,
'xmlns', self::$namespace, ApiResult::NO_SIZE_CHECK );
62 $data = $result->getResultData(
null, [
63 'Custom' =>
static function ( &$data, &$metadata ) {
64 if ( isset( $metadata[ApiResult::META_TYPE] ) ) {
66 switch ( $metadata[ApiResult::META_TYPE] ) {
68 $metadata[ApiResult::META_TYPE] =
'assoc';
73 'BC' => [
'nobool',
'no*',
'nosub' ],
74 'Types' => [
'ArmorKVP' =>
'_name' ],
78 static::recXmlPrint( $this->mRootElemName,
94 public static function recXmlPrint( $name, $value, $indent, $attributes = [] ) {
96 if ( $indent !==
null ) {
97 if ( $name !==
null ) {
100 $indstr =
"\n" . str_repeat(
' ', $indent );
105 if ( is_object( $value ) ) {
106 $value = (array)$value;
108 if ( is_array( $value ) ) {
109 $contentKey = $value[ApiResult::META_CONTENT] ??
'*';
110 $subelementKeys = $value[ApiResult::META_SUBELEMENTS] ?? [];
111 if ( isset( $value[ApiResult::META_BC_SUBELEMENTS] ) ) {
112 $subelementKeys = array_merge(
113 $subelementKeys, $value[ApiResult::META_BC_SUBELEMENTS]
116 $preserveKeys = $value[ApiResult::META_PRESERVE_KEYS] ?? [];
117 $indexedTagName = isset( $value[ApiResult::META_INDEXED_TAG_NAME] )
118 ? self::mangleName( $value[ApiResult::META_INDEXED_TAG_NAME], $preserveKeys )
120 $bcBools = $value[ApiResult::META_BC_BOOLS] ?? [];
121 $indexSubelements = isset( $value[ApiResult::META_TYPE] )
122 && $value[ApiResult::META_TYPE] !==
'array';
126 $indexedSubelements = [];
127 foreach ( $value as $k => $v ) {
128 if ( ApiResult::isMetadataKey( $k ) && !in_array( $k, $preserveKeys,
true ) ) {
133 if ( is_bool( $v ) && !in_array( $k, $bcBools,
true ) ) {
134 $v = $v ?
'true' :
'false';
137 if ( $name !==
null && $k === $contentKey ) {
139 } elseif ( is_int( $k ) ) {
140 $indexedSubelements[$k] = $v;
141 } elseif ( is_array( $v ) || is_object( $v ) ) {
142 $subelements[self::mangleName( $k, $preserveKeys )] = $v;
143 } elseif ( in_array( $k, $subelementKeys,
true ) || $name ===
null ) {
144 $subelements[self::mangleName( $k, $preserveKeys )] = [
146 ApiResult::META_CONTENT =>
'content',
147 ApiResult::META_TYPE =>
'assoc',
149 } elseif ( is_bool( $oldv ) ) {
151 $attributes[self::mangleName( $k, $preserveKeys )] =
'';
153 } elseif ( $v !==
null ) {
154 $attributes[self::mangleName( $k, $preserveKeys )] = $v;
159 if ( $subelements || $indexedSubelements ) {
160 $subelements[self::mangleName( $contentKey, $preserveKeys )] = [
162 ApiResult::META_CONTENT =>
'content',
163 ApiResult::META_TYPE =>
'assoc',
166 } elseif ( is_scalar(
$content ) ) {
169 $attributes += [
'xml:space' =>
'preserve' ];
176 $retval .= $indstr . Xml::element( $name, $attributes,
$content );
178 if ( $name !==
null ) {
179 $retval .= $indstr . Xml::element( $name, $attributes,
null );
181 $retval .= static::recXmlPrint(
null,
$content, $indent );
182 if ( $name !==
null ) {
183 $retval .= $indstr . Xml::closeElement( $name );
186 } elseif ( !$indexedSubelements && !$subelements ) {
187 if ( $name !==
null ) {
188 $retval .= $indstr . Xml::element( $name, $attributes );
191 if ( $name !==
null ) {
192 $retval .= $indstr . Xml::element( $name, $attributes,
null );
194 foreach ( $subelements as $k => $v ) {
195 $retval .= static::recXmlPrint( $k, $v, $indent );
197 foreach ( $indexedSubelements as $k => $v ) {
198 $retval .= static::recXmlPrint( $indexedTagName, $v, $indent,
199 $indexSubelements ? [
'_idx' => $k ] : []
202 if ( $name !==
null ) {
203 $retval .= $indstr . Xml::closeElement( $name );
209 if ( $value ===
null ) {
211 $retval .= $indstr . Xml::element( $name, $attributes );
214 $retval .= $indstr . Xml::element( $name, $attributes, $value );