Now this code was written long ago and I have to fix the problem without changing the current way the file is being loaded to be read and parsed, so I can' t change
doc = New Xml.XPath.XPathDocument(New
IO.MemoryStream(XMLContent)) to Load.XML()
How can I solve the problem for loading the file? once that is resolved, i can take care of the invalid characters in the code.???
got it... you need to replace special characters ( in your case , i think you have probs with spanish characters) with friendly codes.. please refer the below link for friendly codes.
SSpost
Member
256 Points
419 Posts
error loading xml document
Mar 01, 2012 07:25 PM|LINK
When my XML file contains "invalid characters" like é then I get the following error right when the xml is loaded
Error Loading xml document: Invalid character in the given encoding. Line 1, position 1834.
The xml documnet is being loaded in this way in the program
doc =New Xml.XPath.XPathDocument(New IO.MemoryStream(XMLContent))
Now this code was written long ago and I have to fix the problem without changing the current way the file is being loaded to be read and parsed, so I can' t change
doc = New Xml.XPath.XPathDocument(New IO.MemoryStream(XMLContent)) to Load.XML()
How can I solve the problem for loading the file? once that is resolved, i can take care of the invalid characters in the code.???
Shellymn
Contributor
2602 Points
485 Posts
Re: error loading xml document
Mar 01, 2012 08:41 PM|LINK
Please go thorugh this discussion thread for a similar kind of issue..
http://stackoverflow.com/questions/8275825/how-to-prevent-system-xml-xmlexception-invalid-character-in-the-given-encoding
SSpost
Member
256 Points
419 Posts
Re: error loading xml document
Mar 01, 2012 08:47 PM|LINK
The link you provided is for a totally different issue
Shellymn
Contributor
2602 Points
485 Posts
Re: error loading xml document
Mar 01, 2012 09:08 PM|LINK
got it... you need to replace special characters ( in your case , i think you have probs with spanish characters) with friendly codes.. please refer the below link for friendly codes.
http://webdesign.about.com/od/localization/l/blhtmlcodes-sp.htm
SSpost
Member
256 Points
419 Posts
Re: error loading xml document
Mar 01, 2012 09:23 PM|LINK
The problem is , and I am going to describe it again:
When an XML comes with invalid characters like - é , o' (not necessary spanish characters) I get the following error when the xml is loaded.
Error Loading xml document: Invalid character in the given encoding.
And the way the program is loading the xml is
doc = New Xml.XPath.XPathDocument(New IO.MemoryStream(XMLContent))
How do i fix it?
kuber.manral
Contributor
3051 Points
714 Posts
Re: error loading xml document
Mar 02, 2012 03:56 AM|LINK
Hi SSpost,
I guess in this case, you need to put "Encoding" in your overlaod Function like : StreamReader(String, Encoding); For More, Have a look :
http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/c76e593d-c5cf-4399-80056483b53a56e0/
http://stackoverflow.com/questions/6829715/invalid-character-in-the-given-encoding
Hope it helps..
Visit My Blog