c# - xml 错误 : Object reference not set to an instance of an object after SelectSingleNode

标签 c# .net xml

这是我的代码:

XmlDocument doc = new XmlDocument();
foreach (string c in colorList)
{
     doc.Load(@"http://whoisxmlapi.com/whoisserver/WhoisService?domainName=" + c + @"&username=user&password=pass");
     textBox1.Text += doc.SelectSingleNode("WhoisRecord/registrant/email").InnerText + ",";
}

第二行代码 (textbox1...) 产生了这个错误 我做错了什么?

最佳答案

如何拆分行以查看异常发生的位置?

// if node is null the problem is with SelectSingleNode 
XmlNode node = doc.SelectSingleNode("WhoisRecord/registrant/email");

// if text is null the problem is with the node 
string text = node.InnerText;

// if textBox1 is null the problem is with textBox1
textBox1.Text += text + ",";

关于c# - xml 错误 : Object reference not set to an instance of an object after SelectSingleNode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2640402/

相关文章:

c# - 在 C# 中序列化文本与在 JS 中完成的方式相同

c# - 如何在c#中动态删除一个文件?

java - 如何解决 android studio 中的错误 'Package R doesn' t exit' 和 'Execution failed for task":app.compileDebugJavaWithJavac"' 错误?

xml - 使用 XSLT 样式表的奇怪 XML 格式

c# - XML声音的字节格式

c# - ASP.NET MVC 3 中是否有用于类类型声明的 ActionNameAttribute?

c# - 如何在wpf中翻转图像

c# - 在 connectionString C# 中指定 Sql Server Schema

javascript - 如何将带有时区的 json/javascript 日期解析为 C# DateTime?

c# - 我如何告诉 LINQ 忽略不存在的属性?