这是我的代码:
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/