Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
| Search | Today's Posts | Mark Forums Read
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old July 17th, 2003, 06:41 PM
Registered User
Join Date: Jul 2003
Location: , , .
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default XML Traversing using Navigator and Iterator classe


i have a problem here traversing in XML document. i'm trying to use XPathNavigator class, and all i'm trying to do is to print each node's name and its text. can anyone please help me how to do it with Iterator class and navigator class ?

thanx in advance.

following is a sample xml file.

<?xml version='1.0'?>
  <title>XML 1</title>
  <name>Writer 1</name>

  <title>XML 2</title>
  <name>Writer 2</name>

  <title>XML 3</title>
  <name>Writer 3</name>
Old July 18th, 2003, 03:29 AM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts

A bit rough and ready:

using System;
using System.Xml;
using System.Xml.XPath;

namespace LearnXml
    /// <summary>
    /// Walks through an Xml document and outputs node data.
    /// </summary>
    class XmlDocumentor
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
            XPathDocument xpDoc = new XPathDocument(@"E:\scripts\xml\bookstore.xml");
      XPathNavigator xpNav = xpDoc.CreateNavigator();

    static void ProcessElement(XPathNavigator Element)
      XPathNavigator xpTemp = Element.Clone();
      if (xpTemp.NodeType == XPathNodeType.Element)
        Console.WriteLine("Element named '{0}' found.", xpTemp.Name);
        if (xpTemp.HasChildren)
            if (xpTemp.NodeType == XPathNodeType.Element)
            else if (xpTemp.NodeType == XPathNodeType.Text)
              Console.WriteLine("The XML string for this node is '{0}'", xpTemp.Value); 
          while (xpTemp.MoveToNext());
      xpTemp = null;


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help: Arrays using JavaScript,/JSP Iterator in IE celticbhoy Javascript How-To 3 December 11th, 2007 10:55 AM
Iterator Scope Problem smokey_gun Javascript How-To 1 July 4th, 2007 01:26 AM
iterator..... s Larryz C# 2005 0 May 9th, 2007 04:06 PM
Traversing UP my hierarchy in XPath grant6607 XSLT 1 May 11th, 2005 10:02 AM
XML Navigator trouble fzilz BOOK: ASP.NET Website Programming Problem-Design-Solution 1 March 16th, 2004 12:17 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.