Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
This article demonstrates the Elements method, which retrieves a collection of the child elements of an element.
Example: Iterate through the child elements of an element
This example iterates through the child elements of the purchaseOrder element. It uses XML document Sample XML file: Typical purchase order.
XElement po = XElement.Load("PurchaseOrder.xml");
IEnumerable<XElement> childElements =
from el in po.Elements()
select el;
foreach (XElement el in childElements)
Console.WriteLine("Name: " + el.Name);
Dim po As XElement = XElement.Load("PurchaseOrder.xml")
Dim childElements As IEnumerable(Of XElement)
childElements = _
From el In po.Elements() _
Select el
For Each el As XElement In childElements
Console.WriteLine("Name: " & el.Name.ToString())
Next
This example produces the following output:
Name: Address
Name: Address
Name: DeliveryNotes
Name: Items
See also
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.