From string fo DataSet without passing through HTML file
I have a string with length no more than 4000 chars which is a valid xml. Is there a way to pass it to Dataset without creating a temporary xml file? At the moment I do so:
string validXml = TextBox1.Text;
string path = Directory.GetCurrentDirectory() + @"\tmp.xml";
FileInfo xmlProcess = new FileInfo(path);
using (开发者_JS百科StreamWriter sw = xmlProcess.CreateText())
{
sw.WriteLine(validXml);
}
DataSet aDataSet = new DataSet();
aDataSet.ReadXml(reader);
Is there a way to skip this creating and filling the tmp.xml?
Try this:
XmlTextReader reader = new XmlTextReader(new StringReader(validXml));
DataSet aDataSet = new DataSet();
aDataSet.ReadXml(reader);
精彩评论