XElement Class
Represents an XML element.
Assembly: System.Xml.Linq (in System.Xml.Linq.dll)
This class represents an XML element, the fundamental XML construct.
An element has an XName, optionally one or more attributes, and can optionally contain content (for more information, see Nodes).
An XElement can contain the following types of content:
For details about the valid content of an XElement, see Valid Content of XElement and XDocument Objects.
XElement derives from XContainer, which derives from XNode.
Some XElement methods can be used from XAML. For more information, see LINQ to XML Dynamic Properties.
The following example creates an XML tree. The content of the new element comes from a LINQ query.
Dim xmlTree1 As XElement = _ <Root> <Child1>1</Child1> <Child2>2</Child2> <Child3>3</Child3> <Child4>4</Child4> <Child5>5</Child5> <Child6>6</Child6> </Root> Dim xmlTree2 As XElement = _ <Root> <%= From el In xmlTree1.Elements() _ Where el.Value >= 3 And el.Value <= 5 _ Select el %> </Root> Console.WriteLine(xmlTree2)
This example produces the following output:
<Root> <Child3>3</Child3> <Child4>4</Child4> <Child5>5</Child5> </Root>
The following is the same example, but in this case the XML is in a namespace. For more information, see Working with XML Namespaces.
Imports <xmlns="http://www.adventure-works.com"> Module Module1 Sub Main() Dim xmlTree1 As XElement = _ <Root> <Child1>1</Child1> <Child2>2</Child2> <Child3>3</Child3> <Child4>4</Child4> <Child5>5</Child5> <Child6>6</Child6> </Root> Dim xmlTree2 As XElement = _ <Root> <%= From el In xmlTree1.Elements() _ Where el.Value >= 3 And el.Value <= 5 _ Select el %> </Root> Console.WriteLine(xmlTree2) End SUb End Module
This example produces the following output:
<Root xmlns="http://www.adventure-works.com"> <Child3>3</Child3> <Child4>4</Child4> <Child5>5</Child5> </Root>
System.Xml.Linq.XObject
System.Xml.Linq.XNode
System.Xml.Linq.XContainer
System.Xml.Linq.XElement
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.