PHP XMLWriter startDocument创建空白空间

$this->startDocument($this->_xmlVersion, $this->_charSet);

XML parsing failed

XML parsing failed: syntax error (Line: 1, Character: 1)

Error:
XML declaration not at beginning of document 
Specificat`enter code here`ion:
http://www.w3.org/TR/REC-xml/ 
  1:  <?xml version="1.0" encoding="UTF-8"?>
Empty space before <?

How can I remove it?

What are you using? Your code doesn't look like XMLWriter:

$x = new XMLWriter();
$x->openMemory();
$x->startDocument('1.0','UTF-8');
var_dump($x->outputMemory());

This has no extra spaces.

I can be caused by ?> – take a look in your libraries, hooks, etc. and remove it.

try ob_clean() but first make sure that output buffering(ob_start()) is enable.