Site icon Hip-Hop Website Design and Development

Help getting Gutenberg blocks to XML

I’m trying to get Gutenberg blocks as XML so I can export the content but I’m not sure how to do it properly. This is what I have:

function get_blocks($content) {
    
    $blocks = parse_blocks($content);
    $xml = '';
    
    foreach ($blocks as $block) {

        if ($block['blockName'] == 'core/gallery') {
            
            $xml .= "**LT**Gallery**GT**";
            $xml .= $block['innerHTML'];
            $xml .= "**LT**/Gallery**GT**";
            
        } elseif ($block['blockName'] == 'core/paragraph') {
                        
            $xml .= "**LT**Paragraph**GT**";
            $xml .= $block['innerHTML'];
            $xml .= "**LT**/Paragraph**GT**";
            
        } elseif ($block['blockName'] == 'core/video') {
            
            $xml .= "**LT**Video**GT**";
            $xml .= $block['innerHTML'];
            $xml .= "**LT**/Video**GT**";
            
        } else {

            $xml .= "Nothing";

        }
                        
    }
    
    return $xml;

}

I can get the parsed content when returning $blocks (as an array) but the foreach block always returns "Nothing".

Can someone please point me in the right direction? What am I doing wrong? This is for a custom WP All Export feed.

Thank you.