i have this code in c#
d开发者_如何学Coc.SelectSingleNode("WhoisRecord/registrant/email").InnerText
how can i check whether it is returning null?
var n = doc.SelectSingleNode("WhoisRecord/registrant/email");
if (n != null) { // here is the check
DoSomething(n.InnerText);
}
By null
do you mean that the element doesn't exist?
try
{
var n = doc.SelectSingleNode("WhoisRecord/registrant/email");
if (n == string.Empty) {
// empty value
}
// has value
DoSomething(n.InnerText);
}
catch (XPathException)
{
// null value.
throw;
}
I don't sure that it is correct, I need to test it.
//assuming xd is a System.XML.XMLDocument...
XMLNode node = xd.SelectSingleNode("XPath");
if(node == null)
{
//Your error handling goes here?
}else{
// manipulate node.innerText
}
Erm... with the !=
operator - != null
? I'm not sure exactly what you're asking.
精彩评论