I am very new to C# but attempting to make an app to parse a simple XML file like shown below and populate the data inside a multi-column ListView.
<mods>
<mod Name="mod1.zip" sha1="508ed8f5fcd7d323d9296acad76f1183b810f62a"/>
<mod Name="mod2.zip" sha1="669d8d09d297a9724fe1d1d676ac5f5a8ff10277"/>
</mods>
Here is the code I'm trying to work from but it isn't populating the ListView like I'd expect it to..
modList.View = View.Details;
modList.Columns.Add("Name", 650);
modList.Columns.Add("Status", 111, HorizontalAlignment.Center);
XElement root = XElement.Load("https://website.com/modlist.xml");
var mods = from subject in root.Descendants()
where subject.Name.LocalName.Contains("Mod")
select new
{
Name = subject.Element("Name").Value,
Hash = subject.Element("Hash").Value,
};
foreach (var mod in mods)
{
modList.Items.Add(new ListViewItem(new string[]
{
mod.Name,
mod.Hash
}));
}
Modelements, but they're allmodelements. You're also looking for elements calledNameandHash, but they're actually attributes calledNameandsha1. (It's not clear why you're usingContainsrather than just usingroot.Descendants("mod")either.)