Any C# people in here?

Frunple

Active Member
Trying to pull some info from an XML file but having trouble.
Here's the xml:
 

<root
<devices>
<device id="1" name="ZWave"
</device>
</devices>
</root>

I stripped out some unnecessary info,
And here's the C#:
 


XmlNode deviceCollectionNode = doc.SelectSingleNode("/root/devices");

foreach (XmlNode deviceNode in deviceCollectionNode.ChildNodes)
{
if (deviceNode.Name.StartsWith("device"))
{
int veraDeviceID = XmlUtility.GetAttributeString(deviceNode, "id");
_deviceNames[veraDeviceID] = XmlUtility.GetAttributeString(deviceNode, "name");
}
}

Why won't it work?
 
Code:
int veraDeviceID = Convert.ToInt32(deviceNode.Attributes["id"].Value);
_deviceNames[veraDeviceID] = deviceNode.Attributes["name"].Value;
 
Back
Top