I've been trying to make this query work. I have an XML that looks like this:
<Usuarios>
<Usuario>
<username>ghamilton</username>
<nombre>Catherine Hart</nombre>
<fechaNacimiento>12-03-1983 00:00:00</fechaNacimiento>
<nickname>ghamilton</nickname>
<EventosInscripto/>
<Amistades>
<amistad>
<username>dreed</username>
<nombre>Ruby Price</nombre>
<tipo>Aceptado</tipo>
<nickname>dreed</nickname>
<fechaNacimiento>23-12-1986 00:00:00</fechaNacimiento>
</amistad>
<amistad>
<username>ffernandez</username>
<nombre>Michael Rivera</nombre>
<tipo>Aceptado</tipo>
<nickname>ffernandez</nickname>
<fechaNacimiento>07-02-1997 00:00:00</fechaNacimiento>
</amistad>
</Amistades>
</Usuario>
<!-- a lot more 'Usuario' tags after this one -->
<Usuarios/>
What i want to do is get all the Usuarios with the values stored in the tags 'username','nombre','fechaNacimiento', and nickname.
For that I have this code:
XmlNodeList usuarios = xmlDoc.SelectNodes("/Usuarios/Usuario");
foreach (XmlNode usuario in usuarios)
{
//I would use this object to populate a treeview
rg = new Registrado(
xmlNode.SelectSingleNode(@"/username").InnerText,
"NA",
xmlNode.SelectSingleNode(@"/nombre").InnerText,
DateTime.ParseExact(xmlNode.SelectSingleNode(@"/fechaNacimiento").InnerText, "dd-MM-yyyy HH:mm:ss", null),
xmlNode.SelectSingleNode(@"/nickname").InnerText,
null,
null,
null,
null,
true
);
}
But this xPath always selects the first 'usuario' and it's children and doesn't loop through them. It does, actually, loop through the whole document giving the exact ammount of matches, but always with the same data returned.
Any ideas on why my XPath is failing this bad?
Thanks!