I need to read a XML file, I read few guides and I only got confused from weird words that I don't understand (such as nodes, XML validation etc.).
So, could you please walk me through?
I have a XML file which is written in this format:
I want to store it in a dictionary, please show me how can I do it.
Thanks.
Oh, and I'm sorry if this question is too basic and inappropriate.
解决方案var data = XElement.Parse(xml)
.Elements("def")
.ToDictionary(
el => (int)el.Attribute("number"),
el => (string)el.Attribute("name")
);
This:
parses the xml into an XElement (starting at )
iterates over the elements
forms a dictionary, using @number as the key (interpreting as an int), and @name as the value (as a string)
assigns this dictionary to data, which is implicitly typed as Dictionary