什么是的XElement和的XDocument之间的区别? [英] What's the difference between XElement and XDocument?
问题描述
之间的区别是什么的XElement
和的XDocument
,什么时候使用的呢?
What is the difference between XElement
and XDocument
and when do you use each?
推荐答案
的XDocument 重新presents整个XML文档。它通常是由多个元素。
XDocument represents a whole XML document. It is normally composed of a number of elements.
的XElement 重新presents的XML元素(带属性,孩子等)。这是一个更大的文档的一部分。
XElement represents an XML element (with attributes, children etc). It is part of a larger document.
与整个XML文档的XElement与XML元素工作时,工作时使用的XDocument。
Use XDocument when working with a whole XML document, XElement when working with an XML element.
例如 - 的XElement
有一个 HasAttributes
属性指示是否在元素上存在的所有属性,但一个的XDocument
不会,因为这样的属性是没有意义的整个XML文档的内容。
For example - XElement
has a HasAttributes
property indicating whether any attributes exist on the element, but an XDocument
doesn't, as such a property is meaningless in the context of a whole XML Document.
这篇关于什么是的XElement和的XDocument之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!