我想要做的是从字符串(而不是txt文件)获取xml数据。这样做是可行的:
// xmlData.txt contains < m t='Hello' u='1337' />
XmlReader config = new XmlTextReader("../../xmldata.txt");
config.Read();
Console.WriteLine("Data: " + config.GetAttribute("t"));但是我想从字符串而不是文档中解析它。
如何从字符串中解析XML数据?
发布于 2015-01-31 20:39:18
使用StringReader并将其提供给XmlTextReader
StringReader sr = new StringReader("<m t='Hello' u='1337'/>");
XmlReader config = new XmlTextReader(sr);
config.Read();
Console.WriteLine("Data: " + config.GetAttribute("t"));https://stackoverflow.com/questions/28256245
复制相似问题