For example, I got the class Header, and the class Dog.
I would like a file that looks like this:

So far, I have seen no examples to perform this. I must use the
serializer.Serialize because I got a collection of thousands of
objects. Doing otherwise would take too long.
If it is impossible, I will make two different files, one with the
header and the other with the collection of objects, but it is not an
interesting solution.
Edit:
I can’t use a wrapper since I don’t have my complete dog list at the
beginning. I receive one at the time until I stop the application
Thanks a lot!
You will need to create another class the can represent this. For example.
This can then be serialized/deserialized easily.
In answer to your question. If you need the XML to be identical to yours, you will need to create a custom wrapper that will read and write the XML into that specific format.