Destroy XML in the dictionary <string, string>

I have XML;

<data> <name1>James</name1> <name2>John</name2> etc.. </data> 

Name1, name2 etc. can be any, I want this XML to fit perfectly into the dictionary, is this possible using the built-in .net serialization?

Thanks, James.

EDIT: Ideally, I don't want to use linq. Is it possible to serialize the entire array of elements per line? So, I get a string object "Data" containing all the tags of the children and the data?

+4
source share
2 answers

No, but you can use Linq-to-Xml for this:

 XDocument.Load([file path, stream, whatever]).Descendants("data").Descendants() .ToDictionary(element => element.Name, element => element.Value) 

UPDATE: As OP said in his editing, if there is no way to use Linq-to-Xml, then you will need to set up XML serialization IXmlSerializable (you can check this other Q & A: custom XML serialization ).

+8
source

You can use LINQ to XML with the ToDictionary() method;

+1
source

Source: https://habr.com/ru/post/1395586/


All Articles