S
S
Stels0072017-12-18 00:56:17
XML
Stels007, 2017-12-18 00:56:17

xml. How to display elements in a particular node without their children?

Hello! I really ask for help. I rummaged through the entire Internet, I saw 1000 codes, but I did not find the one I needed. The question is:
There is an xml file structure:

<?xml version="1.0" encoding="UTF-8"?>
-<head>
-<Klassi>
<klass>Класс 1</klass>
<klass>Класс 2</klass>
<klass>Класс 3</klass>
<klass>Класс 4</klass>
<klass>Класс 5</klass>
-<klass>Класс 7<gruppa>А</gruppa><gruppa>Б</gruppa><gruppa>В</gruppa></klass></Klassi></head>

I need to count only the elements related directly to the "Klassi" element, i.e. the values ​​of all the "klass" elements, but it turns out that the subelements are also read. This is the vulgar output I manage to get:
"Class 1 Class 2 Class 3 Class 4 Class 5 Class7ABV". Yes, I don’t need ABC, I only need class numbers and that’s it. A mockery of pure water, colleagues! Help me please!
Here is my code:
XmlDocument doc = new XmlDocument();
                    doc.Load("C:\\Gruppi.xml");

                    XmlNodeList nodeList = doc.SelectNodes("head/Klassi/klass");

                    listBox1.Items.Clear();
                    foreach (XmlNode node in nodeList)
                    {
                        listBox1.Items.Add(node.InnerText);
                    }

Ps I don’t know where to cry!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2017-12-18
@Stels007

//Klassi/*/text()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question