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 throws an error 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">
<Rows>
<Row>
<Code />
<Title>Test Title</Title>
</Row>
</Rows>
</iCall>
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);
It is better to use an extra line XmlTextReader xtr = ... and pass xtr to ReadXml method.
DataSet ds = new DataSet();
StringReader sr = new StringReader(strXml); // or xdoc.InnerXml
XmlTextReader xtr = new XmlTextReader(sr);
ds.ReadXml(xtr);
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With