What's the difference between XElement.Load and XDocument.Load?

前端 未结 3 1230
终归单人心
终归单人心 2020-12-30 19:37

As stated above, what\'s the difference between XElement.Load and XDocument.Load? They both seemingly load an XML file.

3条回答
  •  醉话见心
    2020-12-30 20:04

    There are not many scenarios that require you to create an XDocument. Instead, you can usually create your XML trees with an XElement root node. Unless you have a specific requirement to create a document (for example, because you have to create processing instructions and comments at the top level, or you have to support document types), it is often more convenient to use XElement as your root node.

    Straight from Valid Content of XElement and XDocument Objects. As far as the Load methods...they both load content into their respective objects.

提交回复
热议问题