V
V
vladimirchelyabinskiy2016-04-07 15:18:34
C++ / C#
vladimirchelyabinskiy, 2016-04-07 15:18:34

C# how to add a group of elements with attributes after a certain element in XML?

For example, there is a file: test.xml
With elements and attributes.

<student age="12" phone="11111111">
          <name>name</name>
    </student>

I need to add 3 more such elements to this file with the attributes entered in the form.
That is, it should be
<student age="12" phone="11111111">
          <name>name</name>
    </student>
    <student age="13" phone="22222222">
          <name>name</name>
    </student>
    <student age="14" phone="33333333">
          <name>name</name>
    </student>

How to implement it?
Of course, I can simply write all this several times in the program, but what if I have 200 elements?
Should I prescribe them 200 times in the program before compiling?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
V Sh., 2016-04-08
@JuniorNoobie

There are more than one solution.
You can create an XDocument, write XML to it, and work.
You can deserialize the given XML into something like List. Then add the necessary students to this list and serialize the list again.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question