简体   繁体   English

Linq2Xml XAttribute层次结构位置?

[英]Linq2Xml XAttribute hierarchy location?

Im having trouble understanding this : 我无法理解这一点:

在此处输入图片说明

why Microsoft put Xattribute under Xobject ? 为什么Microsoft将Xattribute置于Xobject之下?

they say that : 他们说 :

Attributes are not derived from XNode; 属性不是从XNode派生的。 they are not nodes in the XML tree. 它们不是XML树中的节点。 Instead, they are simply name/value pairs associated with an element. 相反,它们只是与元素关联的名称/值对。

fine ...With an element. 很好 ...带有元素。

so why not where I made a draw ? 那为什么不去哪里抽奖呢?

Attributes belong to an Element. 属性属于元素。

Using inheritance would mean that "an attribute is a (special kind of) Element", which is obviously incorrect. 使用继承将意味着“属性 (一种特殊的)元素”,这显然是错误的。 An attribute cannot have children for example. 例如,属性不能有子级。

The tree is an inheritance tree, it really doesn't show how the objects are used together. 该树是一个继承树,它实际上没有显示如何将对象一起使用。

The location you are suggesting just doesn't work from an inheritance stand point. 从继承的角度来看,您建议的位置不起作用。 Elements can have children and attributes, so if XAttribute was derived from XElement, it would mean that Attributes could have child elements and their own attributes. 元素可以具有子元素和属性,因此,如果XAttribute是从XElement派生的,则意味着Attributes可以具有子元素和它们自己的属性。 The same goes with XContainer, so it doesn't make sense to place XAttribute next to XElement in the tree either. XContainer也是如此,因此在树中将XAttribute放在XElement旁边也没有意义。

XNode is the next step up. XNode是下一步。 Could XAttribute fit under XNode? XAttribute是否适合XNode? Not really. 并不是的。 When you look at an XML, in a general sense, there are 2 basic structural elements, Nodes and Attributes. 一般来讲,当您查看XML时,有两个基本结构元素,即节点和属性。 Neither is derived from the other so it makes sense that XAttribute and XNode be on different branches of the XObject tree. 两者都不是从彼此派生的,因此XAttribute和XNode位于XObject树的不同分支上是有意义的。

That just leaves XObject, which is the base Xml2Linq object type and everything must derive from it, so that is the best (and really only appropriate location) for the XAttribute type. 剩下的就是XObject,它是基本的Xml2Linq对象类型,一切都必须从该对象类型派生,因此,这是XAttribute类型的最佳位置(实际上是唯一适当的位置)。

这是一个继承树,并且XAttribute是从XObject派生的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM