# for a named file, removes the xml declaration

import string, os, sys

filename = sys.argv[1];
#print 'Checking for XML declaration: ' + filename + ' ...';

infile = open( filename, 'r' );
lines = infile.readlines();
infile.close();

start = string.find( lines[0], '<?xml');
end = string.find( lines[0], '?>' ) +2;
if start >= 0:
    print "Found XML declaration and removed.";
    newline = lines[0][:start] + lines[0][end:];
    # print newline;
    outfile = open( filename, 'w' );
    lines[0] = newline;
    if len(lines[0]) > 1:
        outfile.write( lines[0] );
    for line in lines[1:]:
        outfile.write( line );
    outfile.close();
#    print 'Length of first line is ',;
#    print len(newline);
else:
    print "No XML declaration found.";

    

