Error message in Excel when you try to import data from a Web source: "Invalid XML declaration"


Symptoms


When you try to import data from a Web source in Microsoft Excel, you may receive an error message that resembles the following:
File cannot be opened because:
Invalid xml declaration.
This is followed by lines identifying the position of the error and the Extensible Markup Language (XML) version of the file.

Cause


This behavior occurs because the Excel XML parser requires that the characters of the XML tag <?xml?> be absolutely the first characters on the XML page. They cannot be preceded by any other characters, even white space characters that are usually ignored by XML interpreters.

Note The XML parser in Microsoft Excel 2000 does not function under these requirements.

Workaround


To work around this issue, ensure that nothing whatsoever precedes the XML tag in documents that will be opened as Web data sources in Excel.

Status


Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section.

More Information


Well-formed XML documents begin with an XML declaration that identifies them as XML documents and identifies the XML version being used, as in the following example:

<?xml version="1.0"?>
Browsers and other programs that interpret XML generally ignore white-space characters (space, tab, or new line) in the source document, and some XML parsers ignore these characters if they occur ahead of the XML declaration. However, in the case of the XML parser included with Excel, it is essential that none of these characters precede the XML declaration.

The XML parser that is included with Excel 2000, as well as with many browsers, does ignore white-space characters ahead of the XML declaration. As a result, documents that may have opened normally in those environments generate the error message described in the "Symptoms" section of this article when used in Web queries in Excel.