基于此帖子,我想从一些小processing instruction块中读取well-formed XML:>
但是,它不起作用。我得到的错误是pi对象为null。这就是我的工作:
How to read processing instruction from an XML file using .NET 3.5解析XML的作品。当我在Visual Studio中收到错误(System-NullReferenceException)时,我在“ Console.WriteLine(pi.Value);”行得到了它。
哪里出错?如何获取/阅读加工说明?
我想根据这篇文章从一些小的格式良好的XML块中读取处理指令:如何使用.NET 3.5从XML文件读取处理指令但是,它不起作用。我...
XmlDocument doc = new XmlDocument();
doc.LoadXml("<root>Text <?pi 1?>blabla</root>");
Console.WriteLine(doc.ChildNodes[1].Name); // output: root
XmlProcessingInstruction pi = doc.OfType<XmlProcessingInstruction>().Where(x => x.Name == "pi").FirstOrDefault();
Console.WriteLine(pi.Value);