[TYPO3-core] RFC: compact xml2array output

Kasper Skårhøj kasper2006 at typo3.com
Tue Oct 17 23:36:15 CEST 2006


+1

On Oct 17, 2006, at 15:06 , Dmitry Dulepov wrote:

> Hi!
>
> This is SVN patch request.
>
> Branch: 4.0 and trunk
>
> Bug reference: http://bugs.typo3.org/view.php?id=4358
>
> Problem: t3lib_div::xml2array() adds spaces or tabs to generated  
> xml. Sometimes it is good but mostly just takes space without real  
> need. It would be good if this space can be eliminated with a  
> custom option.
>
> Solution: if $spaceInd parameter is negative, do not add space/NL  
> characters. This is compatible with all old applications and does  
> not change behavior of any of them.
>
> This can save a lot of space for templavoila-based sites as well as  
> for plugins with flexform configuration (less than for TV of course).
>
> -- 
> Dmitry Dulepov
>
> Web: http://typo3bloke.net/
> Skype: callto:liels_bugs
>
> "It is our choices, that show what we truly are,
> far more than our abilities." (A.P.W.B.D.)
> Index: t3lib/class.t3lib_div.php
> ===================================================================
> --- t3lib/class.t3lib_div.php	(revision 1762)
> +++ t3lib/class.t3lib_div.php	(working copy)
> @@ -1995,7 +1995,7 @@
>  	 * @param	string		tag-prefix, eg. a namespace prefix like "T3:"
>  	 * @param	integer		Current recursion level. Don't change, stay at  
> zero!
>  	 * @param	string		Alternative document tag. Default is "phparray".
> -	 * @param	integer		If set, the number of spaces corresponding to  
> this number is used for indenting, otherwise a single chr(9) (TAB)  
> is used
> +	 * @param	integer		If greater then zero, than number of spaces  
> corresponding to this number is used for indenting, if less than  
> zero - no indentation, if zero - a single chr(9) (TAB) is used
>  	 * @param	array		Options for the compilation. Key "useNindex" =>  
> 0/1 (boolean: whether to use "n0, n1, n2" for num. indexes); Key  
> "useIndexTagForNum" => "[tag for numerical indexes]"; Key  
> "useIndexTagForAssoc" => "[tag for associative indexes"; Key  
> "parentTagMap" => array('parentTag' => 'thisLevelTag')
>  	 * @param	string		Stack data. Don't touch.
>  	 * @return	string		An XML string made from the input content in  
> the array.
> @@ -2010,6 +2010,7 @@
>  			// Set indenting mode:
>  		$indentChar = $spaceInd ? ' ' : chr(9);
>  		$indentN = $spaceInd>0 ? $spaceInd : 1;
> +		$nl = ($spaceInd >= 0 ? chr(10) : '');
>
>  			// Init output variable:
>  		$output='';
> @@ -2060,7 +2061,7 @@
>  						$clearStackPath = FALSE;
>  					}
>
> -					$content = chr(10).
> +					$content = $nl .
>  								t3lib_div::array2xml(
>  									$v,
>  									$NSprefix,
> @@ -2074,7 +2075,7 @@
>  										'path' => $clearStackPath ? '' : $stackData['path'].'/'. 
> $tagName,
>  									)
>  								).
> -								str_pad('',($level+1)*$indentN,$indentChar);
> +								($spaceInd >= 0 ? str_pad('',($level+1)*$indentN, 
> $indentChar) : '');
>  					if ((int)$options['disableTypeAttrib']!=2)	{	// Do not set  
> "type = array". Makes prettier XML but means that empty arrays are  
> not restored with xml2array
>  						$attr.=' type="array"';
>  					}
> @@ -2083,7 +2084,7 @@
>  						// Look for binary chars:
>  					if (strcspn($v,$binaryChars) != strlen($v))	{	// Go for  
> base64 encoding if the initial segment NOT matching any binary char  
> has the same length as the whole string!
>  							// If the value contained binary chars then we base64- 
> encode it an set an attribute to notify this situation:
> -						$content = chr(10).chunk_split(base64_encode($v));
> +						$content = $nl.chunk_split(base64_encode($v));
>  						$attr.=' base64="1"';
>  					} else {
>  							// Otherwise, just htmlspecialchar the stuff:
> @@ -2094,14 +2095,14 @@
>  				}
>
>  					// Add the element to the output string:
> -				$output.=str_pad('',($level+1)*$indentN,$indentChar).'<'. 
> $NSprefix.$tagName.$attr.'>'.$content.'</'.$NSprefix. 
> $tagName.'>'.chr(10);
> +				$output.=($spaceInd >= 0 ? str_pad('',($level+1)*$indentN, 
> $indentChar) : '').'<'.$NSprefix.$tagName.$attr.'>'.$content.'</'. 
> $NSprefix.$tagName.'>'.$nl;
>  			}
>  		}
>
>  			// If we are at the outer-most level, then we finally wrap it  
> all in the document tags and return that as the value:
>  		if (!$level)	{
>  			$output =
> -				'<'.$docTag.'>'.chr(10).
> +				'<'.$docTag.'>'.$nl.
>  				$output.
>  				'</'.$docTag.'>';
>  		}
> _______________________________________________
> TYPO3-team-core mailing list
> TYPO3-team-core at lists.netfielders.de
> http://lists.netfielders.de/cgi-bin/mailman/listinfo/typo3-team-core

- kasper

"Necessity is the mother of invention"
-------------------------------
kasper2006 at typo3.com | +45 20 999 115 | skype: kasperskaarhoej |  
gizmo: kasper_typo3








More information about the TYPO3-team-core mailing list