I’m trying to create a XML structure (not read/write from/to a file, only the logical part). I’m really confused about how to go about it and what do use. After looking on the Internet I’ve seen two candidate classes: XmlDocument and XDocument (with their corresponding references to nodes, elements, attributes etc.).
One’s got to be deprecated but I’ve checked fairly recent posts (2010 and even 2011) and they are still suggesting code using both variants. Also, the Google check for XDocument only gives a fraction of the hits that XmlDocument brings.
When that part is sorted out, I’ve seen a number of different examples on how to compose a very simple XML structure. I guess the approach depends on the competence level of the person who suggests it, so I’m asking straight out – what classes and what syntax to use?
I had the very same issue a few weeks ago. Apparently, you can’t trust numbers –
XmlDocumentgets roughly 20 times the count hit asXDocumentbut the former is deprecated and the latter is to be used.As for the explanation to this phenomenon, I’m assuming that a lot of code was created using the deprecated class (and by that period’s standards it was a huge convenience to use them). Years later, people are using “what’s working” without realizing that there’s a “new kid on the block”.
And here’s a simple example on how to create a logical XML structure.
More on the subject can be read here.