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

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Date Time
8.Design Patterns
9.Development Class
10.Event
11.File Stream
12.Generics
13.GUI Windows Form
14.Internationalization I18N
15.Language Basics
16.LINQ
17.Network
18.Office
19.Reflection
20.Regular Expressions
21.Security
22.Services Event
23.Thread
24.Web Services
25.Windows
26.Windows Presentation Foundation
27.XML
28.XML LINQ
C# / C Sharp » XML LINQ » Nodes 




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.
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.