0

I am trying to read from web service (ODATA) an XML and save the data at DataSet. The problem is that there are Unicode characters I can not read.

My code looks like that:

        String URLString = "SomeUrl";
        DataSet ds = new DataSet();
        ds.ReadXml(URLString);

What is the simplest way to get the data with the Unicode characters and save it in DataSet?

Thank you!

Maor.I
  • 47
  • 9
  • What do you mean with 'Unicode characters I can not read'? What error do you get? – Hintham Mar 29 '18 at 15:34
  • @Hintham The purpose is that it's reading, for example, a text in Hebrew (in that case) as âìéåï instead of בדיקה. There is encoding problem I think, that I don't know how to fix. – Maor.I Mar 29 '18 at 17:18
  • Net doesn't accept unicode definition in first line of the xml. So you need to skip the first line. So I usually use followng : StreamReader reader = new StreamReader(filename, Encoding.Unicode); reader.ReadLine(); ds.ReadXml(reader); – jdweng Mar 29 '18 at 22:13
  • We really need a [mcve] to answer this question property. The [reference source](https://referencesource.microsoft.com/#System.Data/System/Data/DataSet.cs,2150) shows that `DataSet` uses the obsolete `XmlTextReader` to download the XML. It wouldn't surprise me if it got the encoding wrong. – dbc Mar 30 '18 at 16:01
  • Try passing the `XmlReader` returned by [`XmlReader.Create(URLString)`](https://msdn.microsoft.com/en-us/library/w8k674bf(v=vs.110).aspx) into [`DataSet.ReadXml(XmlReader)`](https://msdn.microsoft.com/en-us/library/d6swf149(v=vs.110).aspx) to see if that fixes the problem. Alternatively, you could try downloading the manually as a string using the newer `HttpClient` or `WebClientExtensions.DownloadStringAwareOfEncoding()` from [WebClient.DownloadString() returns string with peculiar characters](https://stackoverflow.com/a/30049848/3744182). – dbc Mar 30 '18 at 16:02

0 Answers0