What's the difference between XElement and XDocument?

前端 未结 4 894
鱼传尺愫
鱼传尺愫 2020-12-29 04:09

What is the difference between XElement and XDocument and when do you use each?

4条回答
  •  青春惊慌失措
    2020-12-29 04:15

    From MSDN:

    Note that you only have to create XDocument objects if you require the specific functionality provided by the XDocument class. In many circumstances, you can work directly with XElement. Working directly with XElement is a simpler programming model.

    XDocument derives from XContainer. Therefore, it can contain child nodes. However, XDocument objects can have only one child XElement node. This reflects the XML standard that there can be only one root element in an XML document.

提交回复
热议问题