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 ) ) {
110 $subelementKeys = array_merge(
125 $indexedSubelements = [];
126 foreach ( $value as $k => $v ) {
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 ) {
148 } elseif ( is_bool( $oldv ) ) {
152 } elseif ( $v !==
null ) {
158 if ( $subelements || $indexedSubelements ) {
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 );
223 private static function mangleName( $name, $preserveKeys = [] ) {
224 static $nsc =
null, $nc =
null;
226 if ( in_array( $name, $preserveKeys,
true ) ) {
230 if ( $name ===
'' ) {
234 if ( $nsc ===
null ) {
238 $nsc =
'A-Za-z\x{C0}-\x{D6}\x{D8}-\x{F6}\x{F8}-\x{2FF}\x{370}-\x{37D}\x{37F}-\x{1FFF}' .
239 '\x{200C}-\x{200D}\x{2070}-\x{218F}\x{2C00}-\x{2FEF}\x{3001}-\x{D7FF}' .
240 '\x{F900}-\x{FDCF}\x{FDF0}-\x{FFFD}\x{10000}-\x{EFFFF}';
241 $nc = $nsc .
'_\-.0-9\x{B7}\x{300}-\x{36F}\x{203F}-\x{2040}';
244 if ( preg_match(
"/^[$nsc][$nc]*$/uS", $name ) ) {
248 return '_' . preg_replace_callback(
251 return sprintf(
'.%X.', UtfNormal\Utils::utf8ToCodepoint( $m[0] ) );
253 str_replace(
'.',
'.2E.', $name )