I'm getting a NullReferenceException
upon trying to read an attribute of an xml-file - what attribute to read from what element is defined by user-input.
The StackTrace keeps redirecting me to this line (marked)
XmlDocument _XmlDoc = new XmlDocument();
_XmlDoc.Load(_WorkingDir + "Session.xml");
XmlElement _XmlRoot = _XmlDoc.DocumentElement;
XmlNode _Node = _XmlRoot.SelectSingleNode(@"group[@name='" + _Arguments[0] + "']");
XmlAttribute _Attribute = _Node.Attributes[_Arguments[1]]; // NullReferenceException
Where did I miss the point? What Reference is missing here? I can't figure it out...
Edit: The element exists and so does the attribute (including a value)
<?xml version="1.0" encoding="utf-8"?>
<session>
<group name="test1" read="127936" write="98386" />
<group name="test2" read="352" write="-52" />
<group name="test3" read="73" write="24" />
<group name="test4" read="264524" write="646243" />
</session>
Further explanation: The _Arguments[]
is a splitted array of the user input. The user e.g. inputs test1_read
- that is splitted to _Arguments[0] = "test"
and _Arguments[1] = "read"