My XML file is as:
<?xml version="1.0" encoding="UTF-8"?>
<Settings>
<SurveySetting IsServeyOn="false" />
</Settings>
I want to fetch the value of IsServeyOn.
I write the below code for that:
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(filepath);
XmlElement root = xmlDoc.DocumentElement;
XmlNode node = root.SelectSingleNode("//SurveySetting");
RadiobuttonSurverysetting.SelectedValue = node.Attributes["IsServeyOn"].Value;
But sometimes it gives me error.. Node not found or NUll.
Is any other way to select the node?
nodebeingnullindicates there is no<SurveySetting>element in your document. Are you absolutely sure that element is always present?NULL.. Use//SurveySetting[not(@IsServeyOn)]//SurveySetting[@IsServeyOn], in case the element exists but its attribute doesn't?