Craft 2 - Returning Value in Variable from Plugin to Template
You're close, you don't necessarily need another class or function. Though you may want to change the function name to be a bit more clear, and you may want to move the heavy XML logic into a separate private method.

class AiPaginationTestVariable
{
        public function getXml($params = null)
        {
            // Compile XML
            $xml = $this-&gt;_compileXml($params);

            // Return XML or false
            if ($xml) {
                return $xml;
            } else {
                return false;
            }
        }

        private function _compileXml($params = null)
        {
            // Whatever it takes to compile XML
        }
}


Then in your Twig template, you can do something like this...

{% set xml = craft.aiPaginationTest.getXml() %}

{% if false == xml %}
    {# Handle no XML #}
{% endif %}


This might not directly answer your question, but I hope it's enough to get  you back on track.