From the course: .NET Essentials: LINQ for XML
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Get nodes when using schema namespace - .NET Tutorial
From the course: .NET Essentials: LINQ for XML
Get nodes when using schema namespace
- [Instructor] There is an additional step necessary when you want to get an element that is in a file that has a schema specified within a namespace. Now, I'm looking at this file, BigStarCollectibles. You can see in my root element, Collectibles, I have a default namespace specified here. It has no prefix. This is called the default namespace. And then I provide this unique URI here. So it's bigstarcollectibles.com/course-examples. So if I want to get to this card element, I need to specify this namespace too. So over here, in LINQPad, I am loading BigStarCollectibles.xml that I'm specifying on line eight this variable of type X namespace, and you can see that the matches what I showed you over in the XML file. And then it's just a matter of concatenating the two together. So when I call dot element, I can concatenate these two together. This is the name of the element I want. And when I run this, I get the results I want.…
Contents
-
-
-
-
Get an element from XML2m 33s
-
Get an attribute from XML1m 25s
-
Get nodes when using schema namespace3m 32s
-
Get single or multiple elements2m 27s
-
Get child element1m 12s
-
Get child elements1m 58s
-
Use Descendants() to recurse child elements52s
-
Get attributes51s
-
Read element and attribute values1m 32s
-
Change element and attribute values1m 36s
-
Use SetElementValue to add, remove, and modify child elements1m 37s
-
Use SetValue to set with non-string data1m 4s
-
-
-
-