Reputation: 6281
I'm getting sometimes the error "Text node cannot appear in this state" in my application after editing a xml in MonoDevelop and loading it with dotNET. This error is really annoying, because i have to copy the XML-file to windows and try to fix it there with VS.
The xml file is absolutly correct, must be something with the encoding. Is there any quick way to fix this in MonoDevelop?
And of course, it would be interesting why this error appears.
<?xml version="1.0" encoding="UTF-8"?>
<Data>
</Data>
Upvotes: 2
Views: 6773
Reputation: 526
I was trying to reproduce this problem and I found that (given my contrived reproduction) that all I had to do was edit the first line of the xaml
<?xml version="1.0" encoding="UTF-8"?>
It appears as though, when the encoding changed, that there was a single space before the <?xml
node in the file. I used TextWrangler to open the file and saw the space. Simply editing the file in Xamarin Studio resolved the issue. In further investigation it looked as though there were 2 BOMs in the header of the file.
fe ff fe ff
I'd love to hear back if anyone can pinpoint how the encoding changed though.
Upvotes: 3
Reputation: 18449
I think the problem is that the Byte Order Mark appears as the first 2 bytes, and a parser that doesn't expect a byte order mark will interpret it as a short text node. Re-encoding without the BOM should fix it.
Upvotes: 1
Reputation: 6281
I found only one workaround for this error when using monodevelop only( There are other ways to solve this issue by using another editor ):
Saving the file with another encoding ( UTF-16 ). This is not going to solve it permanently, if you edit the file again it may occur again.
Upvotes: 1