c#-将XmlReader转换为XmlTextReader
作者:互联网
如何将XmlReader转换为XmlTextReader?
代码段:
XmlTextReader reader = XmlTextReader.Create(pomfile.FullName);
这是我得到的生成错误:
Cannot implicitly convert type 'System.Xml.XmlReader' to 'System.Xml.XmlTextReader'. An
存在显式转换(您是否缺少演员表?).
pomfile的类型为FileInfo
解决方法:
XmlTextReader.Create()函数生成XMLReader,您必须将其强制转换为XmlTextReader,但如果无法强制转换,则会产生运行时异常:
XmlTextReader tr = (XmlTextReader)XmlTextReader.Create(pomfile.FullName));
或者您可以这样做:
XmlTextReader reader = new XmlTextReader(XmlTextReader.Create(pomfile.FullName));
但最好的办法是:
XmlTextReader reader = new XmlTextReader(pomfile.FullName);
标签:xmlreader,xmltextreader,c 来源: https://codeday.me/bug/20191210/2101878.html