Hello.

I wrote the user.xml file in this way

<Пользователь>Афанасий</Пользователь> <Пол>Мужчина</Пол> <Дата> <Год>1988</Год> <Месяц>5</Месяц> <День>5</День> <Род деятельности>Путешествия</Род деятельности> </Дата> <Пользователь>Марина</Пользователь> <Пол>Женский</Пол> <Дата> <Год>1968</Год> <Месяц>2</Месяц> <День>12</День> <Род деятельности>Путешествия</Род деятельности> </Дата> <Пользователь>Димон</Пользователь> <Пол>Мужчина</Пол> <Дата> <Год>1588</Год> <Месяц>5</Месяц> <День>31</День> <Род деятельности>Путешествия</Род деятельности> </Дата> 

I want the program to read the file, select the data, and put it in a variable. Example: today is 03/28/12, and if the program sees that there is a date of 3.04.12 or less, then transfer them to variables

 int day = 0; int month = 0; int year = 0; 

Well, and continue to work with them, just XML for me is something new, I searched on YouTube, I did not find it, on MSDN there is too much for everyone, and it’s not clear where there is something that you end up confusing.

    2 answers 2

    Xml documents parse well LINQ'om.

     XElement source = XElement.Load(@"source.xml"); var parsed = (from date in source.Descendants("Дата") let d = new { Day = date.Element("День").Value, Month = date.Element("Месяц").Value, Year = date.Element("Год").Value } select d) .ToArray(); 

    Now there is no place to check, but it should work.

    • Error: There are multiple root elements. Line 2, position 2. - Angus123
    • four
      wrap everything in <xml> </ xml> - Ilmirus
    • How to do it? - Angus123
    • At the beginning of the document (first line), enter <xml> , at the end of the document, on the last character, insert </xml> . - vmp1r3

    There are several ways to write data to an Xml file:

    1. Serialization. Using the System.Runtime.Serialization.Xml you can easily write data to Xml files. For this, the XmlFormatter class is XmlFormatter .
    2. Linq to XML. Data is System.Xml.Linq , read and edited with the System.Xml.Linq namespace.
    3. You can also read and write data using the System.Xml namespace.

    For a detailed study of the information, I recommend reading the manual in Russian:

    1. http://metanit.com/sharp/tutorial/6.4.php
    2. http://metanit.com/sharp/tutorial/16.5.php
    3. http://metanit.com/sharp/tutorial/16.1.php

    Reference to the manual, for each item, respectively.

    PS XML tags are not recommended to write in Cyrillic, use Latin characters.