I am trying to check if node "DEF" exists in my xml file
My xml file looks like this:
<Struct>
<A>
<ABC>
</ABC>
<DEF>
</DEF>
</A>
<B>
<GHI>
</GHI>
</B>
</Struct>
And my code looks like this:
XmlDocument stru = new XmlDocument();
stru.Load(path + "Structure.xml");
if (stru.ChildNodes[0].HasChildNodes)
{
for (int i = 0; i < stru.ChildNodes[0].ChildNodes.Count; i++)
{
if (stru.ChildNodes[0].ChildNodes[i].Attributes["DEF"] != null)
{
enabled = true;
break;
}
else
{
MessageBox.Show("no");
}
}
}
else { MessageBox.Show("Error!"); }
And it immediately shows messagebox with "Error!" in it