C# XML如何检查节点是否返回null?
我有c语言的代码#C# XML如何检查节点是否返回null?,c#,xml,C#,Xml,我有c语言的代码# 如何检查它是否返回空值?呃。。。用=操作员-!=空值?我不确定你到底在问什么。Bynull你的意思是元素不存在吗 var n = doc.SelectSingleNode("WhoisRecord/registrant/email"); if (n != null) { // here is the check DoSomething(n.InnerText); } //assuming xd is a System.XML.XMLDocument... XMLNode
如何检查它是否返回空值?呃。。。用
=代码>操作员-!=空值
?我不确定你到底在问什么。Bynull
你的意思是元素不存在吗
var n = doc.SelectSingleNode("WhoisRecord/registrant/email");
if (n != null) { // here is the check
DoSomething(n.InnerText);
}
//assuming xd is a System.XML.XMLDocument...
XMLNode node = xd.SelectSingleNode("XPath");
if(node == null)
{
//Your error handling goes here?
}else{
// manipulate node.innerText
}
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,这里没有:-/
try
{
var n = doc.SelectSingleNode("WhoisRecord/registrant/email");
if (n == string.Empty) {
// empty value
}
// has value
DoSomething(n.InnerText);
}
catch (XPathException)
{
// null value.
throw;
}