I wrote this code to check if a XmlNode has a value, but when I run it crash always on the !=null. It is strange because this solution is well known.
private static void TraverseNodes(XmlNodeList nodes)
{
foreach (XmlNode node in nodes)
{
if (!node.HasChildNodes)
{
Console.WriteLine(node.Name + " " + node.Attributes["id"].Value);
}
if (node.Attributes["SplitCombinationOperator"].Value != null)
{
Console.WriteLine(node.Name + " " + node.Attributes["SplitCombinationOperator"].Value);
}
else
{
Console.WriteLine(node.Name);
}
TraverseNodes(node.ChildNodes);
}
}
The error is the following: Object reference not set to an instance of an object.