views:

57

answers:

2

I'm reading a string into a dataset using the ReadXML method. When I try that it returns an Invalid Characters in the path error. if I save and open the string in IE as an xml file it erros on the encoding="UTF-16" line so I assume that is the cause of the problem.

Is there a simple way to fix this? Shouldn't it be able to handle unicode or UTF-16?

Any suggestions would be much appreciated. Using C# & .Net 4

<?xml version="1.0" encoding="UTF-8" ?> <iCall xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt; <Rows> <Row> <Code /> <Title>Test Title</Title> </Row> </Rows> </iCall>

+1  A: 

I think you can try to use ReadStartElement to advance to the next node and read the whole table into DataSet.

XmlTextReader r = new XmlTextReader(@"c:\b.xml");
r.MoveToContent();
r.ReadStartElement("iCall");
DataSet ds = new DataSet();
ds.ReadXml(r);
this.dataGrid1.DataSource = ds;
Vinay B R
+1  A: 

DataSet.ReadXml(string) expects a file path not an xml document. So it tries to parse your xml document as a filepath and fails

if you only have your XML runtime, then you can do like this:

StringReader sr = new StringReader(xml);
dataSet.ReadXml(sr);
Rune FS