From the course: .NET Essentials: LINQ for XML
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Get attributes - .NET Tutorial
From the course: .NET Essentials: LINQ for XML
Get attributes
- [Instructor] An element can have 0 or more attributes, so there has to be a way of getting a single attribute, or a collection of attributes and this is the syntax for that. If you want a single attribute, you call .attribute and you provide the name, and you get the attribute value, the name value pair back. If you want to get the IEnumerable Xattribute you call attributes, this will return all of the attributes that are in this element. Here it has five items: card name, team name, rarity, collector number and card family. This also works when you're working with IEnumerables of elements. So let's change this top line here and say I want elements. So I want all the elements, all cards, there's 7 of them. And then I want all the attributes that are on all the cards. So now when I run this, I get back 35 items in this IEnumerable.
Contents
-
-
-
-
(Locked)
Get an element from XML2m 33s
-
(Locked)
Get an attribute from XML1m 25s
-
(Locked)
Get nodes when using schema namespace3m 32s
-
(Locked)
Get single or multiple elements2m 27s
-
(Locked)
Get child element1m 12s
-
(Locked)
Get child elements1m 58s
-
(Locked)
Use Descendants() to recurse child elements52s
-
(Locked)
Get attributes51s
-
(Locked)
Read element and attribute values1m 32s
-
(Locked)
Change element and attribute values1m 36s
-
(Locked)
Use SetElementValue to add, remove, and modify child elements1m 37s
-
(Locked)
Use SetValue to set with non-string data1m 4s
-
(Locked)
-
-
-