Blank line in output affecting XML

I have seen this before, but can’t trace where it’s coming from and I
searched high and low. When I try to output an XML file (like
/Search/Results.rdf), I am getting an error:

XML Parsing Error: xml declaration not at start of external entity
Location: http://rtdev/Search/test.xml
Line Number 2, Column 1:

<?xml version="1.0" encoding="UTF-8"?>

^

Because no matter what I output, the declaration is starting on line 2 of
the output. Then I noticed that this happens on all pages, but HTML doesn’t
care as much that the doctype declaration or html element are on the very
first line… However, XML does. If I save the file, kill the first line
and reload it, it’s fine.

I made the following completely simple file to output which has no RT calls
at all (except that it’s in the RT root, so handled by webmux.pl and
RT::Mason). I stuck it in local/html/Search/test.xml and it returns the
above error.

#–begin code snippet –
<%INIT>
$r->content_type(‘application/xml’);

print <<EOF;

<?xml version="1.0" encoding="UTF-8"?> simple test EOF

$m->abort();
</%INIT>
#–end code snippet –

This must not be a problem for all since RSS has been around in RT for a
couple of versions, so I’m assuming that I have some module that is above
the “required” version, but is still causing this problem. Can anyone point
me to the right place to figure this out?

RT 3.6.3rc4
Perl 5.8.8
Mod_perl 2.0.2
HTML::Mason 1.3.5
(I can list others if anyone can tell me which ones to be looking at).

Thanks
Erik

Erik Peterson
Education Development Center, Inc.

Because no matter what I output, the declaration is starting on line 2 of
the output. Then I noticed that this happens on all pages, but HTML doesn’t
care as much that the doctype declaration or html element are on the very
first line… However, XML does. If I save the file, kill the first line
and reload it, it’s fine.

After a bunch more searching, I found the problem (or at least a solution).

http://lists.fsck.com/pipermail/rt-devel/2004-January/005362.html

This thread mentions that the same problem cropped up when dealing with PNG
output and that the solution was to clear the Mason buffer before using
$m->out();

The line is just

$m->clear_buffer();

Before outputting anything and all is right with the world.

Don’t know if anyone else can use this, but figured it would be nice to
close the loop on this question.

Thanks,
Erik