Select All Child Nodes : XPath « XML « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » XML » XPath 
30.21.28.Select All Child Nodes
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;

public class MainClass
{

    public static void Main()
    {
        XmlDocument mDocument = new XmlDocument();
        XmlNode mCurrentNode;

        mDocument.Load("XPathQuery.xml");
        mCurrentNode = mDocument.DocumentElement;


        XmlNodeList nodeList = mCurrentNode.SelectNodes("*");
        DisplayList(nodeList);
    }

    static void DisplayList(XmlNodeList nodeList)
    {
        foreach (XmlNode node in nodeList)
        {
            RecurseXmlDocumentNoSiblings(node);
        }
    }

    static void RecurseXmlDocumentNoSiblings(XmlNode root)
    {
        if (root is XmlElement)
        {
            Console.WriteLine(root.Name);
            if (root.HasChildNodes)
                RecurseXmlDocument(root.FirstChild);
        }
        else if (root is XmlText)
        {
            string text = ((XmlText)root).Value;
            Console.WriteLine(text);
        }
        else if (root is XmlComment)
        {
            string text = root.Value;
            Console.WriteLine(text);
            if (root.HasChildNodes)
                RecurseXmlDocument(root.FirstChild);
        }
    }
    static void RecurseXmlDocument(XmlNode root)
    {
        if (root is XmlElement)
        {
            Console.WriteLine(root.Name);
            if (root.HasChildNodes)
                RecurseXmlDocument(root.FirstChild);
            if (root.NextSibling != null)
                RecurseXmlDocument(root.NextSibling);
        }
        else if (root is XmlText)
        {
            string text = ((XmlText)root).Value;
            Console.WriteLine(text);
        }
        else if (root is XmlComment)
        {
            string text = root.Value;
            Console.WriteLine(text);
            if (root.HasChildNodes)
                RecurseXmlDocument(root.FirstChild);
            if (root.NextSibling != null)
                RecurseXmlDocument(root.NextSibling);
        }
    }
}
30.21.XPath
30.21.1.XPath Select Nodes
30.21.2.Append child from XPathNavigator
30.21.3.Append new node to XPathNavigator
30.21.4.Using XPath to filter data from Database
30.21.5.Using XPathNavigator to loop through code
30.21.6.Using XPathNodeIterator
30.21.7.XPath Navigator
30.21.8.XPath Node Iterator
30.21.9.XPath Selecting: /Customers/Customer[@FirstName='D']
30.21.10.XPath XSLT transformation
30.21.11.XPath selecting: descendant::Customer[@FirstName='D']
30.21.12.XPath selecting: descendant::Customer[EmailAddress='k@a.com']
30.21.13.XPath selecting: descendant::Customer[attribute::FirstName='D']
30.21.14.XPath selecting: descendant::Customer[contains(EmailAddress, 'a.com')]
30.21.15.XPath selecting: descendant::Customer[starts-with(@LastName, 'G') and contains(EmailAddress, 'a.com')]
30.21.16.XPath selecting: descendant::EmailAddress[text()='k@a.com']
30.21.17.XPathNavigator and TreeView
30.21.18.Xpath Demo: //attribute[@name='capacity'] | //attribute[@name='weight']
30.21.19.Xpath Demo: /items/item
30.21.20.Xpath Demo: /items/item/attribute[@value > 10 and @name='weight']
30.21.21.Xpath Demo: /items/item[2]
30.21.22.Create XPathNavigator
30.21.23.Move to first child in XPathNavigator
30.21.24.Compile XPath to create XPathExpression
30.21.25.Read sub tree from XPathNavigator
30.21.26.Select All Author Nodes
30.21.27.Select All Books
30.21.28.Select All Child Nodes
30.21.29.Select XPath from XPathNavigator
30.21.30.Set new value through XPathNavigator
30.21.31.Show innter xml and outer xml from XPathNavigator
30.21.32.Sorting XPathExpression with XmlSortOrder.Ascending, XmlCaseOrder.None
30.21.33.Using XPathExpression to sort by first name
30.21.34.Select node with asterisk
30.21.35.Use the XPath return type to determine how to process the XPath expression
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.