How to get the label number one or an xml file in c #?

0

What I want is to get the children of my tag videos, which in this case would be Mathematics, but when I execute my code c # I get the children of my Mathematical tag, what is being Tema1.

<?xml version="1.0" encoding="utf-8"?>
<Videos>
  <Matematica>Tema1</Matematica>
</Videos>

Code C #

XmlDataDocument xmldoc = new XmlDataDocument();
            XmlNodeList xmlnode;
            FileStream fs = new FileStream(directorio + "XML\videos.xml", FileMode.Open, FileAccess.Read);
            xmldoc.Load(fs);
            xmlnode = xmldoc.GetElementsByTagName("Videos").Item(0).ChildNodes;

            for (int i=0;i<=xmlnode.Item(0).ChildNodes.Count;i++)
            {
                listado.Add(xmlnode.Item(i).InnerText);

            }

            return listado;
    
asked by David 28.05.2018 в 22:39
source

1 answer

1

InnerText returns the text of the node, in this case, the text of the node Matematica . If you want to get the name of the node, then use the Name property:

//...
for (int i=0;i<=xmlnode.Item(0).ChildNodes.Count;i++){
   listado.Add(xmlnode.Item(i).Name);
}
//...
    
answered by 28.05.2018 / 22:49
source