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
|