How to read XML string from DB into XMLTextReader?
Ihave an issue with reading an XML string into XMLTextReader..
I'm querying the a DB and getting a DataSet back. From that DataSet, I'm reading a specific row and column (which contains XML strings) and using that XML string value开发者_StackOverflow to pass to an XMLTextReader. The problem is that I'm getting the error "Illegal Character in path".
I know that the XML string returned from the DB is proper, as I can open the XML in my browser.
This is the code I'm using:
string XMLstring = DS.Tables[0].Rows[i][y].ToString();
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(XMLstring);
StringWriter sw = new StringWriter();
XmlTextWriter xw = new XmlTextWriter(sw);
xmlDoc.WriteTo(xw);
XmlTextReader textReader = new XmlTextReader(sw.ToString());
Any ideas why I'm getting this error??
Thanks!
Look at the XMLTextReader constructor overloads. You're trying to load an XML string, and the String overload expects a path.
Try writing the XML string out to a file, and give the XMLTextReader that file's path.
精彩评论