FirstNode, LastNode, and Nodes

FirstNode and LastNode give you direct access to the first or last child node.

Nodes returns all children as a sequence.

All three functions consider only direct descend- ants. For example:


using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;

class Program
{
    static void Main()
    {
        var address = new XElement("address",new XElement("street", "Main St"), new XElement("town", "New York"));
        var customer1 = new XElement("customer1", address);
        var customer2 = new XElement("customer2", address);

        foreach (XNode node in address.Nodes())
            Console.WriteLine(node.ToString(SaveOptions.DisableFormatting) + ".");

    }
}

The output:

Main St.
		New York.
  
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.