Hello. There is a treeview.

How to write TreeViewItem-s in pieces of different terms and subsections in different xml files?

TreeView looks like this:

ΠšΠΎΠΌΠΏΡŒΡŽΡ‚Π΅Ρ€Π½Π°Ρ Π³Ρ€Π°Ρ„ΠΈΠΊΠ° Π’Π΅Ρ€ΠΌΠΈΠ½Ρ‹ 2D 3D Π“Ρ€Π°Ρ„ΠΈΠΊΠ° ΠšΠΎΠΌΠΏΡŒΡŽΡ‚Π΅Ρ€ ΠšΠ°Π΄Ρ€ Π˜Π½Ρ„ΠΎΡ€ΠΌΠ°Ρ‚ΠΈΠΊΠ° ΠœΠΎΠ½ΠΈΡ‚ΠΎΡ€ ПиксСль ΠŸΠΎΠ΄Ρ€Π°Π·Π΄Π΅Π»Ρ‹ 3D Π³Ρ€Π°Ρ„ΠΈΠΊΠ° Π’Π΅Ρ€ΠΌΠΈΠ½Ρ‹ Π“Ρ€Π°Ρ„ΠΈΠΊΠ° ΠœΡƒΠ»ΡŒΡ‚ΠΈΠΏΠ»ΠΈΠΊΠ°Ρ†ΠΈΡ Космос Π§Π΅Π»ΠΎΠ²Π΅ΠΊ МодСль ΠŸΠΎΠ΄Ρ€Π°Π·Π΄Π΅Π»Ρ‹ 2D анимация Π’Π΅Ρ€ΠΌΠΈΠ½Ρ‹ Π˜Π·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅ ΠšΠΎΡ€Ρ€Π΅ΠΊΡ†ΠΈΡ ΠΊΠ°Π΄Ρ€Π° Π’ΠΈΡ‚Ρ€Ρ‹ ΠŸΠΎΠ΄Ρ€Π°Π·Π΄Π΅Π»Ρ‹ 2,5 D CGI Π³Ρ€Π°Ρ„ΠΈΠΊΠ° Π’Π΅Ρ€ΠΌΠΈΠ½Ρ‹ Π¦Π²Π΅Ρ‚Π° Випография RGB CMYK ΠŸΠΎΠ΄Ρ€Π°Π·Π΄Π΅Π»Ρ‹ РСальная сторона Π³Ρ€Π°Ρ„ΠΈΠΊΠΈ 

To get something like this:

a1.xml

 <Razdel>ΠšΠΎΠΌΠΏΡŒΡŽΡ‚Π΅Ρ€Π½Π°Ρ Π³Ρ€Π°Ρ„ΠΈΠΊΠ°</Razdel> <TerminVRazdele> <Termin>ΠœΠΎΠ½ΠΈΡ‚ΠΎΡ€</Termin> </TerminVRazdele> <TerminVRazdele> <Termin>ПиксСль</Termin> </TerminVRazdele> <Podrazdeli> <Podrazdel>3D Π³Ρ€Π°Ρ„ΠΈΠΊΠ°</Podrazdel> </Podrazdeli> <Podrazdeli> <Podrazdel>CGI Π³Ρ€Π°Ρ„ΠΈΠΊΠ°</Podrazdel> </Podrazdeli> 

a1-1.xml

 <Razdel>3D Π³Ρ€Π°Ρ„ΠΈΠΊΠ°</Razdel> <TerminVRazdele> <Termin>Π“Ρ€Π°Ρ„ΠΈΠΊΠ°</Termin> </TerminVRazdele> <TerminVRazdele> <Termin>ΠœΡƒΠ»ΡŒΡ‚ΠΈΠΏΠ»ΠΈΠΊΠ°Ρ†ΠΈΡ</Termin> </TerminVRazdele> <Podrazdeli> <Podrazdel>2D анимация</Podrazdel> </Podrazdeli> 

a1-1-1.xml

 <Razdel>2D анимация</Razdel> <TerminVRazdele> <Termin>Π˜Π·ΠΎΠ±Ρ€Π°ΠΆΠ΅Π½ΠΈΠ΅</Termin> </TerminVRazdele> <TerminVRazdele> <Termin>ΠšΠΎΡ€Ρ€Π΅ΠΊΡ†ΠΈΡ ΠΊΠ°Π΄Ρ€Π°</Termin> </TerminVRazdele> <TerminVRazdele> <Termin>Π’ΠΈΡ‚Ρ€Ρ‹</Termin> </TerminVRazdele> <Podrazdeli> <Podrazdel>2,5 D</Podrazdel> </Podrazdeli> 

    2 answers 2

    TreeView has no method for writing to the xml file, and indeed in any other format. Therefore, in any case, the method will have to write yourself. The easiest in my opinion is to translate the necessary TreeView branches into a DataTable, and DataTable already has a standard writing method in XML format.

      No one has yet canceled the usual way of writing to a file. Read the Node and Items from the tree, and write to the file (line by line), and then save it in the required format.

      • As I tried, I made several for loops at the beginning. In 1, the file is written normally. Other identical lines are written when writing subsections in depth, it does not read. How to make recording subsections correctly? - Demon
      • It is possible and the DataTable is not important by what method to write the main contents of the files so that it is as in the example so far only one file is obtained - Demon
      • Are there any examples on this issue in the internet did not find anything - Demon
      • Go around in the loop all the nodes of the tree, and select the data! I do not remember by heart, especially Saturday, evening :) But access to the elements of the TreeView is in any reference manual! Generate XML tags yourself, insert tree data for them - that's all! So they made reports in HTML format, selected data and went to write, something like this WriteLn ("<p>" + Value + "</ p>"). Programming language does not matter. - Vyacheslav Kirichenko
      • I practically do so. At the stage of traversal of children this happens. Only for me every time TreeViewItem should have a new value, and it gets the old value and writes it to the file. - Demon