Calling the Only Nodes Prototype : Nodes « XML LINQ « C# / C Sharp






Calling the Only Nodes Prototype

  

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using System.Xml.Linq;
public class MainClass {
    public static void Main() {
        XDocument xDocument = new XDocument(
         new XElement("Books",
           new XElement("Book",
            new XAttribute("type", "Author"),
           new XComment("This is a new author."),
            new XElement("FirstName", "A"),
           new XElement("LastName", "B")),
           new XElement("Book",
            new XAttribute("type", "Author"),
           new XElement("FirstName", "C"),
           new XElement("LastName", "D"))));

        IEnumerable<XElement> elements = xDocument.Element("Books").Elements("Book");
        foreach (XElement element in elements) {
            Console.WriteLine("Source element: {0} : value = {1}", element.Name, element.Value);
        }
        foreach (XNode node in elements.Nodes()) {
            Console.WriteLine("Child node: {0}", node);
        }
    }
}

   
  








Related examples in the same category

1.Traversing Backward from an XElement Object via the PreviousNode Property
2.Adds the specified content immediately after this node.
3.Adds the specified content immediately before this node.
4.Returns a collection of the ancestor elements of this node.
5.Returns a filtered collection of the ancestor elements of this node.
6.Creates an XmlReader for this node.
7.Use hard coded xsl to convert xml document
8.Returns a collection of the sibling elements after this node, in document order.
9.Returns a filtered collection of the sibling elements after this node, in document order.
10.Returns a collection of the sibling elements before this node, in document order.
11.Returns a filtered collection of the sibling elements before this node, in document order.
12.Determines if the current node appears after a specified node in terms of document order.
13.Determines if the current node appears before a specified node in terms of document order.
14.Gets the next sibling node of this node.
15.Returns a collection of the sibling nodes after this node, in document order.
16.Returns a collection of the sibling nodes before this node, in document order.
17.Gets the previous sibling node of this node.
18.Removes this node from its parent.
19.Replaces this node with the specified content.
20.Returns the XML for this node, optionally disabling formatting.
21.Returns the indented XML for this node.
22.Writes this node to an XmlWriter.