[英]SelectSingleNode returning null for known good xml node path using XPath
[英]XML how to check if node is returning null?
我在c#中有这段代码
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
表示元素不存在?
try
{
var n = doc.SelectSingleNode("WhoisRecord/registrant/email");
if (n == string.Empty) {
// empty value
}
// has value
DoSomething(n.InnerText);
}
catch (XPathException)
{
// null value.
throw;
}
我不确定它是否正确,我需要测试它。
//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
? 我不确定你究竟在问什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.