PC Review


Reply
Thread Tools Rate Thread

C# - Using XML MoveToNext and generating a Path

 
 
DeTon8R
Guest
Posts: n/a
 
      22nd Nov 2007
Hi all,

I am aiming to build a path directory which will be created upon
collecting element values, like this:

XPathNavigator nav;
XPathDocument docNav;

docNav = new XPathDocument(@"docname.xml");
//Create a navigator to query with XPath
nav = docNav.CreateNavigator();

//Initialise XPathNavigator to start at the root.
nav.MoveToRoot();
string rootelement = nav.Value;


//Move to the first child node
nav.MoveToFirstChild();
string element1 = nav.Value;

//Step into next element
nav.MoveToNext();
string element2 = nav.Value;

Another class will then go through each values and check if the
directory exists and build them if not like so:

try
{
// Determine whether the directory exists.
if (!Directory.Exists(rootelement))
{
// Create the directory it does not exist.
Directory.CreateDirectory(rootelement);
}
try
{
// Determine whether the directory exists.
if (!Directory.Exists(rootelement/element1))
{
// Create the directory it does not exist.
Directory.CreateDirectory(rootelement/element1);
}

etc etc


My query is, is there an easier way of doing this, as i would need to
know when MoveToNext reaches the final element. Can this be somehow
done using a foreach statement?

Many Thanks
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to judge whether a path is relative path or absolute path thinktwice Microsoft Windows 2000 CMD Promt 20 7th May 2008 11:06 PM
C# - Using XML MoveToNext and generating a Path DeTon8R Microsoft C# .NET 0 22nd Nov 2007 01:51 PM
Outlook Bar: Can I find out a shortcut's original path if the destination path has been moved deleted? Dame Joselyn Van Hire Microsoft Outlook Discussion 0 12th Jan 2007 02:39 PM
set path, change path - path grayed out John Smith Windows XP Help 1 12th Feb 2005 01:56 PM
set path, change path - path grayed out John Smith Windows XP General 1 12th Feb 2005 01:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:34 PM.