public static function xmlEncode( $hash, $childName = 'child' )
    {
        $xml = new XmlWriter();
        $xml->openMemory();
        $xml->startDocument('1.0', 'UTF-8');
        $xml->startElement('root');

        self::xmlWrite( $xml, $hash, $childName );

        $xml->endElement();
        return $xml->outputMemory( true );

    }