Question

Im having trouble understanding this :

enter image description here

why Microsoft put Xattribute under Xobject ?

they say that :

Attributes are not derived from XNode; they are not nodes in the XML tree. Instead, they are simply name/value pairs associated with an element.

fine ...With an element.

so why not where I made a draw ?

Was it helpful?

Solution

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. The same goes with XContainer, so it doesn't make sense to place XAttribute next to XElement in the tree either.

XNode is the next step up. Could XAttribute fit under XNode? Not really. When you look at an XML, in a general sense, there are 2 basic structural elements, Nodes and Attributes. Neither is derived from the other so it makes sense that XAttribute and XNode be on different branches of the XObject tree.

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.

OTHER TIPS

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.

This is an inheritance tree and XAttribute is derived from XObject.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top