Actualización: noviembre 2007
Representa un elemento HTML.
Ensamblado: System.Xml.Linq (en System.Xml.Linq.dll)
Public Class XElement _ Inherits XContainer _ Implements IXmlSerializable
Dim instance As XElement
public class XElement : XContainer, IXmlSerializable
public ref class XElement : public XContainer, IXmlSerializable
public class XElement extends XContainer implements IXmlSerializable
public class XElement extends XContainer implements IXmlSerializable
Esta clase representa un elemento XML, la construcción XML fundamental.
Un elemento tiene un objeto XName, puede tener uno o varios atributos y, de manera opcional, puede incluir el contenido (para obtener más información, vea Nodes).
XElement puede incluir los siguientes tipos de contenido:
-
XElement
Para obtener información detallada sobre el contenido válido de XElement, vea Contenido válido de objetos XElement y XDocument.
XElement deriva de XContainer, que deriva de XNode.
Algunos métodos XElement se pueden usar desde XAML. Para obtener más información, vea Propiedades dinámicas de LINQ to XML.
En el siguiente ejemplo se crea un árbol XML. El contenido del nuevo elemento proviene de una consulta LINQ.
XElement xmlTree1 = new XElement("Root", new XElement("Child1", 1), new XElement("Child2", 2), new XElement("Child3", 3), new XElement("Child4", 4), new XElement("Child5", 5), new XElement("Child6", 6) ); XElement xmlTree2 = new XElement("Root", from el in xmlTree1.Elements() where((int)el >= 3 && (int)el <= 5) select el ); Console.WriteLine(xmlTree2);
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)
Este ejemplo produce el siguiente resultado:
<Root> <Child3>3</Child3> <Child4>4</Child4> <Child5>5</Child5> </Root>
A continuación se muestra el mismo ejemplo, pero en este caso el XML está en un espacio de nombres. Para obtener más información, vea Trabajar con espacios de nombres XML.
XNamespace aw = "http://www.adventure-works.com"; XElement xmlTree1 = new XElement(aw + "Root", new XElement(aw + "Child1", 1), new XElement(aw + "Child2", 2), new XElement(aw + "Child3", 3), new XElement(aw + "Child4", 4), new XElement(aw + "Child5", 5), new XElement(aw + "Child6", 6) ); XElement xmlTree2 = new XElement(aw + "Root", from el in xmlTree1.Elements() where((int)el >= 3 && (int)el <= 5) select el ); Console.WriteLine(xmlTree2);
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
Este ejemplo produce el siguiente resultado:
<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 Vista, Windows XP SP2, Windows Server 2003, Windows CE, Windows Mobile para Smartphone, Windows Mobile para Pocket PC
.NET Framework y .NET Compact Framework no admiten todas las versiones de cada plataforma. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.