我在C#中的代码XML如何检查节点是否返回空值?
doc.SelectSingleNode("WhoisRecord/registrant/email").InnerText
我怎么能检查它是否返回null?
我在C#中的代码XML如何检查节点是否返回空值?
doc.SelectSingleNode("WhoisRecord/registrant/email").InnerText
我怎么能检查它是否返回null?
var n = doc.SelectSingleNode("WhoisRecord/registrant/email");
if (n != null) { // here is the check
DoSomething(n.InnerText);
}
呃...与!=
运营商 - != null
?我不确定你在问什么。
//assuming xd is a System.XML.XMLDocument...
XMLNode node = xd.SelectSingleNode("XPath");
if(node == null)
{
//Your error handling goes here?
}else{
// manipulate node.innerText
}
通过null
您是否指该元素不存在?
try
{
var n = doc.SelectSingleNode("WhoisRecord/registrant/email");
if (n == string.Empty) {
// empty value
}
// has value
DoSomething(n.InnerText);
}
catch (XPathException)
{
// null value.
throw;
}
我不确定它是否正确,我需要测试它。
惊喜!假设doc是一个XmlDocument,这里没有一个: - / – 2010-04-15 04:45:29