Today, I found an error on the MSDN forum that I encountered and suffered from in the past. If you are working with BizTalk schemas or processing incoming XML files, you may have encountered this frustrating error:
“Unexpected XML declaration. The XML declaration must be the first node in the document, and no white space characters are allowed to appear before it. Line 1, position 4.”
📝 One-Minute Brief
This error typically occurs when a BizTalk schema or XML message contains hidden characters, spaces, or Byte Order Marks (BOM) before the tag. Even a single empty space or a newline at the very beginning of the file will cause the XML parser to fail. The solution involves opening the file in a text editor (like Notepad++), enabling “Show All Characters,” and deleting any leading whitespace or invisible characters before the declaration.
The error message is quite literal, but the cause is often invisible to the naked eye.
Cause
- You have a single whitespace character on the first line of your schema before the start of the XML declaration.
Or
- You have a single whitespace character on the first line of your XML file before the start of the XML declaration.
Solution 1
- Open your XSD file in Notepad and remove the character, save, and then re-validate- the problem should go away.
Solution 2
- When using an XML file, you must start the declaration in the first row with <?xml version=”1.0″ encoding=”UTF-8″ ?> right away. No space is allowed at the beginning of the XML file.
While this error seems minor, XML parsers are strictly designed to follow this rule. By ensuring your files start at “Position 0,” you can avoid deployment failures and runtime processing errors.
great….i was did this error from last two days…now solved it..thanks
I am facing this issue while calling a WCF service. surprisingly the message states Line(44,9) or Line(46,9) when the request is not more than 26 lines. I am still clueless. Can anyone share their experience