2010-04-15 104 views

回答

7
var n = doc.SelectSingleNode("WhoisRecord/registrant/email"); 
if (n != null) { // here is the check 
    DoSomething(n.InnerText); 
} 
0

呃...与!=运营商 - != null?我不确定你在问什么。

1
//assuming xd is a System.XML.XMLDocument... 
XMLNode node = xd.SelectSingleNode("XPath"); 
if(node == null) 
{ 
//Your error handling goes here? 
}else{ 
// manipulate node.innerText 
} 
2

通过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; 
} 

我不确定它是否正确,我需要测试它。

+0

惊喜!假设doc是一个XmlDocument,这里没有一个: - / – 2010-04-15 04:45:29