src/XML/DOM/Formater.php
public static function recode( $xml, $encodeTo = "UTF-8" )
	{
		$validator	= new XML_DOM_SyntaxValidator();
		if( !$validator->validate( $xml ) )
			throw new InvalidArgumentException( 'String is no valid XML' ); 

		$encodeTo	= strtoupper( $encodeTo );
		
		$document	= new DOMDocument();
		$document->loadXml( $xml );
		$encoding	= strtoupper( $document->actualEncoding );
#		remark( "Encoding: ".$encoding );
		if( $encoding == $encodeTo )
			return $xml;
		
		$pattern		= '@<\?(.*) encoding=(\'|")'.$encoding.'(\'|")(.*)\?>@i';
		$replacement	= '<?\\1 encoding="'.$encodeTo.'"\\4?>';
		$xml	= iconv( $encoding, $encodeTo, $xml );
		$xml	= preg_replace( $pattern, $replacement, $xml );
		return $xml;
	}
public static function recode( $xml, $encodeTo = "UTF-8" )
	{
		$validator	= new XML_DOM_SyntaxValidator();
		if( !$validator->validate( $xml ) )
			throw new InvalidArgumentException( 'String is no valid XML' ); 

		$encodeTo	= strtoupper( $encodeTo );
		
		$document	= new DOMDocument();
		$document->loadXml( $xml );
		$encoding	= strtoupper( $document->actualEncoding );
#		remark( "Encoding: ".$encoding );
		if( $encoding == $encodeTo )
			return $xml;
		
		$pattern		= '@<\?(.*) encoding=(\'|")'.$encoding.'(\'|")(.*)\?>@i';
		$replacement	= '<?\\1 encoding="'.$encodeTo.'"\\4?>';
		$xml	= iconv( $encoding, $encodeTo, $xml );
		$xml	= preg_replace( $pattern, $replacement, $xml );
		return $xml;
	}
public static function recode ( $ xml , $ encodeTo = "UTF-8" ) { $ validator = new XML_DOM_SyntaxValidator ( ) ; if ( ! $ validator -> validate ( $ xml ) ) throw new InvalidArgumentException ( 'String is no valid XML' ) ; $ encodeTo = strtoupper ( $ encodeTo ) ; $ document = new DOMDocument ( ) ; $ document -> loadXml ( $ xml ) ; $ encoding = strtoupper ( $ document -> actualEncoding ) ; #		remark( "Encoding: ".$encoding ); if ( $ encoding == $ encodeTo ) return $ xml ; $ pattern = '@<\?(.*) encoding=(\'|")' . $ encoding . '(\'|")(.*)\?>@i' ; $ replacement = '<?\\1 encoding="' . $ encodeTo . '"\\4?>' ; $ xml = iconv ( $ encoding , $ encodeTo , $ xml ) ; $ xml = preg_replace ( $ pattern , $ replacement , $ xml ) ; return $ xml ; }
Recodes a XML String to another Character Set.
@access		public
@static
@param		string		$xml		XML String to format
@param		string		$encodeTo	Character Set to encode to
@see		http://www.iana.org/assignments/character-sets
@return		string
Recodes a XML String to another Character Set .