473,387 Members | 1,483 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Arrays and folders

I have an XML file with some data:

<Directlist>
<Directory>
<ID>1</ID>
<name>DirectoryRed</name>
</Directory>
<Directory>
<ID>2</ID>
<name>DirectoryBlue</name>
</Directory>
<Directory>
<ID>3</ID>
<name>DirectoryWhite</name>
</Directory>
</Directlist>

Is there a way i can read only the <name> (DirectoryRed, DirectoryBlue,
DirectoryWhite) into an array and then generate Folders using a method like
this (example):

public static void CreateDirectory(string directory)
{
string path = directory;
try
{
if (!Directory.Exists(path))
{
// Create the directory it does not exist.
Directory.CreateDirectory(path);
}
}
catch (Exception e)
{
MessageBox.Show("Creating directory failed: {0}", e.ToString());
}
finally {}
}

THe result will be 3 new folders
best regards
Trond
Nov 16 '05 #1
3 1338
Hi Trond

Use XPath

XmlDocument doc = new XmlDocument();
doc.Load(<your XML in some form>);
XmlNodeList nodes = doc.SelectNodes("//name/text()");
foreach( XmlNode node in nodes)
{
if( !Directory.Exists(node.Value)
{
Directory.CreateDirectory(node.Value);
}
}

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

I have an XML file with some data:

<Directlist>
<Directory>
<ID>1</ID>
<name>DirectoryRed</name>
</Directory>
<Directory>
<ID>2</ID>
<name>DirectoryBlue</name>
</Directory>
<Directory>
<ID>3</ID>
<name>DirectoryWhite</name>
</Directory>
</Directlist>

Is there a way i can read only the <name> (DirectoryRed, DirectoryBlue,
DirectoryWhite) into an array and then generate Folders
Nov 16 '05 #2
Thank you wery much. XPath is new to me but i see now that i should spend
some time learning it. You saved me a lot of time now :-)
Best regards
Trond

"Richard Blewett [DevelopMentor]" <ri******@develop.com> wrote in message
news:ur**************@TK2MSFTNGP11.phx.gbl...
Hi Trond

Use XPath

XmlDocument doc = new XmlDocument();
doc.Load(<your XML in some form>);
XmlNodeList nodes = doc.SelectNodes("//name/text()");
foreach( XmlNode node in nodes)
{
if( !Directory.Exists(node.Value)
{
Directory.CreateDirectory(node.Value);
}
}

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

I have an XML file with some data:

<Directlist>
<Directory>
<ID>1</ID>
<name>DirectoryRed</name>
</Directory>
<Directory>
<ID>2</ID>
<name>DirectoryBlue</name>
</Directory>
<Directory>
<ID>3</ID>
<name>DirectoryWhite</name>
</Directory>
</Directlist>

Is there a way i can read only the <name> (DirectoryRed, DirectoryBlue,
DirectoryWhite) into an array and then generate Folders

Nov 16 '05 #3
Yep, XPath is definitely thre most efficient (in terms of the amount of code you have to write) way of getting data out of an XmlDocument. But you have to be happy to take the hit (which for small documents isn't a big deal) to load the document into memory. For big documents you may have to drop down to using XmlReader but in most situations it isn't necessary.

One last thing, Xpath is *very* xml namespace sensitive. If the document you showed isn't exactly like the document you are processing (like there is a default namespace or something) then you have more work to do.

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<41********@news.broadpark.no>

Thank you wery much. XPath is new to me but i see now that i should spend
some time learning it. You saved me a lot of time now :-)
Best regards
Trond
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Karuppasamy | last post by:
Hi I want to populate all the files and folders of System in a Treeview control like Windows Explorer. I try this using File System Objects. But sometimes I am getting an error like 'Access...
5
by: George Hester | last post by:
If I have 1 Virtual Dirctory with 2 different subfolders are these 2 different folders different virtual folders? Or if I have 2 different Virtual Directories each containing a subfolder are these...
1
by: Jason Steeves | last post by:
Does anyone know an easy way to get all of the folders and their sub-folders and their sub-folders and so on? I need to get all of the folders and their paths from an inputted parent folder...
4
by: Noa | last post by:
Hi, Is there a way to use OpenFileDialog1 in order to multi-select folders? I saw in msdn site a sample of multi-file-selections. I need to select multiple folders and to apply an algorithm on...
0
by: Bob | last post by:
Hi, I'm new to Python and I want to create a script that will import contactitems into an Outlook Public Folder. Therefore I've installed the Python for Windows Extensions. This way I can...
3
by: sva | last post by:
Using C# for an application in which I am working on, I need to display the available shared folders on the computer that's running the application. The shared folder paths need to be in UNC format...
1
by: =?Utf-8?B?UmFjaW5yaG9uZGE=?= | last post by:
I had a hard drive failure and had to re-load Microsoft Office XP. When I first loaded, I had no data files so I imported my pst files from my old hard drive and now I have double of everything...
5
by: Per Juul Larsen | last post by:
Hi. My application creates empty libraries. How do I ensure that the user copies at least one or more picture files (.jpg) in each of the empty folders ? Result , no empty folders! regards pjl
1
by: veer | last post by:
hi it looks a silly question but i m getting confused actually i want to copy folders from one location to another like from C:\abc To D:\xyz here abc and xyz are two folders in c and d drive it...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.