XmlReader problem when XML has non foreign special characters [modified]
-
Hello! I have a problem, I'm trying to read an XML-file that may contain characters from different languages, like for example swedish, danish or german non-ascii characters. when i load the reader into my xmlDoc, i get an exception telling me that one of the caracters is invalid. is there any setting i can do to make the xmlreader ignore what kind of caracters the element includes? Can i have something to do with the header (i have xml-files with no header) example xml: normal äää-not-normal kind regards Andreas -- modified at 2:52 Friday 4th August, 2006
-
Hello! I have a problem, I'm trying to read an XML-file that may contain characters from different languages, like for example swedish, danish or german non-ascii characters. when i load the reader into my xmlDoc, i get an exception telling me that one of the caracters is invalid. is there any setting i can do to make the xmlreader ignore what kind of caracters the element includes? Can i have something to do with the header (i have xml-files with no header) example xml: normal äää-not-normal kind regards Andreas -- modified at 2:52 Friday 4th August, 2006
-
Specify the encoding when you create the streamreader. Example:
StreamReader reader = new StreamReader(fileName, Encoding.GetEncoding("windows-1250"));
--- b { font-weight: normal; }
I recommend fixing the XML document instead of trying to make your program read invalid XML. See for example here[^] The default encoding is UTF-8, if you use anything else you must a) Specify it in the header b) Kill yourself to save the world from yet more ANSI junk. Only exception is if you use another Unicode encoding (UTF-16 for example), but normally this is not needed. :)
-
Hello! I have a problem, I'm trying to read an XML-file that may contain characters from different languages, like for example swedish, danish or german non-ascii characters. when i load the reader into my xmlDoc, i get an exception telling me that one of the caracters is invalid. is there any setting i can do to make the xmlreader ignore what kind of caracters the element includes? Can i have something to do with the header (i have xml-files with no header) example xml: normal äää-not-normal kind regards Andreas -- modified at 2:52 Friday 4th August, 2006
First of all, what is your code, what reader are you using? An xml reader, DOM, SAX, or a text reader? No doc type (header)?? That's actually not valid XML. Is it possible to include it? Short of a Byte order mark, w/o the doc type there is NO way to accurately figure out the encoding of file. If you can't add the doc type to your XML doc, you must specify the encoding in your code. UTF-8 would be a safe guess. -- modified at 3:03 Sunday 6th August, 2006 -- modified at 3:04 Sunday 6th August, 2006
/\ |_ E X E GG