I'm writing some code that opens an XML file, reads it and stores the data in a List. The only thing is that I get "XmlException data at the root level is invalid " when I run my code. I've searched on the error and non of the solutions worked for me (or I missed something).
My XML (* = censor):
<?xml version="1.0" encoding="utf-8" ?>
<Users>
<User id="1" email="***" password="***">***</User>
<User id="2" email="***" password="***">***</User>
</Users>
My C# code:
XmlDocument doc = new XmlDocument();
doc.Load("Users.xml");
XmlNode UserListNode = doc.SelectSingleNode("/Users");
XmlNodeList UserNodeList = UserListNode.SelectNodes("User");
foreach (XmlNode node in UserNodeList)
{
Users user = new Users();
user.id = Convert.ToInt16(node.Attributes.GetNamedItem("id").Value);
user.name = node.InnerText;
user.email = node.Attributes.GetNamedItem("email").Value;
user.password = node.Attributes.GetNamedItem("password").Value;
users.Add(user);
}
Anyone who could help?