There can be two cases –
case 1 – If you have an empty space before the first statement.
case 2 – If you have accidently put the same namespacing statement twice ie – ?xml version=”1.0″ encoding=”utf-8″?
I did it once and landed with the same error of yours after correcting it my code runs fine.