i have an xml string and i want to read data from it.
<?xml version="1.0" encoding="utf-16"?>
<Tree AllowNodeEditing="True" ShowLineImages="False" CheckBoxes="True"
EnableAjaxSkinRendering="False" AutoPostBackOnCheck="True" AutoPostBack="True">
<Node Enabled="False" Text="Geen afbeeldingen aanwezig"
Checked="True" Selected="True" thumb="" tekst="" />
<Node Text="IMG_2807 (Small).JPG"
Value="../../CMS/Images/Fotogalerie/552/IMG_2807 (Small).JPG" tekst="Afbeelding IMG_2807 (Small).JPG"
thumb="../../CMS/Images/Thumbs/552/IMG_2807 (Small).JPG" />
please note that in third line Node enabled=False.
I am using the code
XDocument doc = XDocument.Parse(strFile);
var values = (from f in doc.Elements().Descendants()
select f.Attribute("Value").Value).ToArray();
and this throws an error..
You need to null check the value because if you do
select f.Attribute("Value").Valuewithout null checking, it will throw an exception if the element doesn’t have theValueattribute.Looking at your sample XML not all
Nodeshave the attributeValue.Try this instead: