开发者

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜