This is no valid XML. Have a look at the XML specs for documents:
document ::= prolog element Misc*
prolog ::= XMLDecl? Misc* (doctypedecl Misc*)?
XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'
document
decribes what other grammar tokens XML documents are build from, starting with a prolog
. This may contain an XMLDecl
, which again starts with <?xml
. In short: there is no whitespace allowed before the declaration, if there is one.
If you are under control of the XML (which you seem to be): Just don't do that, I'd regard this to be malicious as everybody having to deal with the code after you will wonder what's going on.
If you cannot change the input, because somebody else is sending broken XML files:
- tell him to ship well-formed XML or
- "preprocess" the non-XML with
trim($string)
like already proposed in the comments.