By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,247 Members | 871 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,247 IT Pros & Developers. It's quick & easy.

Directory Scanning

P: n/a
I would like to scan a directory structure into XML to offer navigation
functionality in HTML / XSL pages.

My questions are:

1. Which is the best structure to store variable depth heirarchies in
XML (i.e. different branches of the directory structure will have
different 'depths').

2. I am currently using VBA to prepare the pages and export to XML and
was wondering if there are any tools around which will save me the
coding 'leg-work'? (i.e. directly transfer the directory structures
into XML)

Any tips on either of these points would be a great help to me.

Many thanks,
Alan Searle.
Feb 18 '06 #1
Share this Question
Share on Google+
10 Replies


P: n/a
Alan,

to store dirs i use normaly the HTML-like syntax like

<ul>
<li>usr
<ul>
<li>local</li>
</ul>
</li>
</ul>

that has 2 advantages:

1) For HTML-Output i can use a simple xsl:copy-of ...
2) For creating and manipulation you can use recursivity, that makes
your code thin you just need one method that calls itself, if there are
children.

Hope that helps.

Cheers,
Dominik

Feb 18 '06 #2

P: n/a
fedro wrote:
Alan,

to store dirs i use normaly the HTML-like syntax like

<ul>
<li>usr
<ul>
<li>local</li>
</ul>
</li>
</ul>

that has 2 advantages:

1) For HTML-Output i can use a simple xsl:copy-of ...
2) For creating and manipulation you can use recursivity, that makes
your code thin you just need one method that calls itself, if there are
children.

Hope that helps.

Cheers,
Dominik


That is really a bad xml format for a directory structure.
The tags should say something about the data.

I would like this better:

<file name="dir1">
<file name="dir2">
<file name="file.xml"/>
</file>
<file name="config.txt">
</file>

You can view directories as files too.
One problem: symbolic links can result in endless recursion.

Feb 19 '06 #3

P: n/a
On Sun, 19 Feb 2006 18:49:05 +0100, Tjerk Wolterink
<tj***@wolterinkwebdesign.com> wrote:
You can view directories as files too.


Not a good idea in XML though. The idea that "directories are a funny
sort of file" is an artefact of some _implementations_ of file systems.
As far as data modelling goes it's not the sort of coincidental factor
that should be preserved into a more abstract representation.

For one thing (and relevant to XML / DTD design) what should the content
model be for the children of this "file or directory" node ? Does it
have child nodes (as a directory does) or not (as a file does) ?
"Borrowing" HTML elements is bad software design too because it's
confusing the fact that these are entirely separate elements because
they're taken from separate namespaces. Relying on copy-of working and
giving the elements matching local-name() properties is piss-poor
software engineering. Look up a textbook from back when such things were
last taught (1980s ?) and lookup the concept of "coupling".
Feb 19 '06 #4

P: n/a
> That is really a bad xml format for a directory structure.

No it isn't!

What is a directory at least? It is an unordered list of items wich
contains other unorderd lists of items. And that is exactly, what my
tag <ul> with * children of <li> (=ListIitems) stands for.

You can extend the <li> tags with more information, i.e.
modifiedDate="20060219184905", extension="pdf" tags an so on.

With the extension-Attribute it is realy simple to create Icons for the
list by CSS.

And, Tjerk, with your solution it is not very easy (and so not very
fast ..) to know if a children is a subdirectory or a file.

Follow the KISS principle.

Cheers,
Dominik

Feb 20 '06 #5

P: n/a
Hi everyone,

I have been fishing around on other forums and have found a really easy
(DOS command) way of 'grabbing' directory trees ...

dir c:\mydir /a:d /b /s>dirs.txt

It was a big relief to find that.

And regarding directory trees, I think I will first try an adapted
version of Fedro's HTML suggestion. Mine would include files and
properties and would look something like the following ...

<root>
<startdir>mylocaldir1
<dir>dir1
<file>file1
<creationdate>20060211</creationdate>
<owner>John Smith</owner>
</file>
<file>Another file
</file>
</dir>
<dir>Another directory
<file>Yet another file
</file>
</dir>
</startdir>
</root>

I would store complete directory paths which might get a bit long but at
this stage, simplicity is probably the best. I'll then see how my
navigation mechanisms pan out and may need to review the structure.
Indeed, I am even pondering storing a parallel XML file in the more
'pure' (fragmented) format, containing a link ID that would enable
navigation to be based on the 'pure' XML and then information retrieval
using the HTML style structure.

Thanks for your tips and comments as these have really helped to get me
thinking about the problem.

And I hope that my feedback is useful for you?

All the best,
Alan Searle.

Andy Dingley schrieb:
On Sun, 19 Feb 2006 18:49:05 +0100, Tjerk Wolterink
<tj***@wolterinkwebdesign.com> wrote:

You can view directories as files too.

Not a good idea in XML though. The idea that "directories are a funny
sort of file" is an artefact of some _implementations_ of file systems.
As far as data modelling goes it's not the sort of coincidental factor
that should be preserved into a more abstract representation.

For one thing (and relevant to XML / DTD design) what should the content
model be for the children of this "file or directory" node ? Does it
have child nodes (as a directory does) or not (as a file does) ?
"Borrowing" HTML elements is bad software design too because it's
confusing the fact that these are entirely separate elements because
they're taken from separate namespaces. Relying on copy-of working and
giving the elements matching local-name() properties is piss-poor
software engineering. Look up a textbook from back when such things were
last taught (1980s ?) and lookup the concept of "coupling".

Feb 20 '06 #6

P: n/a
Alan Searle wrote:
<file>file1
<creationdate>20060211</creationdate>


Put the filename into an attribute, not the element's content. You have
child elements in there too (unavoidably so for directories) and
processing mixed content is always a real pain.

Feb 20 '06 #7

P: n/a
OK :-)

Thanks very much for the tip.

Cheers,
Alan.

Andy Dingley <di*****@codesmiths.com> schrieb:
Alan Searle wrote:

<file>file1
<creationdate>20060211</creationdate>

Put the filename into an attribute, not the element's content. You have
child elements in there too (unavoidably so for directories) and
processing mixed content is always a real pain.

Feb 20 '06 #8

P: n/a
Alan Searle wrote:
1. Which is the best structure to store variable depth heirarchies in
XML (i.e. different branches of the directory structure will have
different 'depths').
XML structure is a tree. Directory structure is a tree (barring
additional links/symlinks). Map the latter to the former, however makes
most stense for your application.
coding 'leg-work'? (i.e. directly transfer the directory structures
into XML)


Find a code example of walking a directory tree. Alter it to output XML.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Feb 22 '06 #9

P: n/a
Hi Joe,
1. Which is the best structure to store variable depth heirarchies in
XML (i.e. different branches of the directory structure will have
different 'depths').

XML structure is a tree. Directory structure is a tree (barring
additional links/symlinks). Map the latter to the former, however makes
most stense for your application.


OK. But other contributers have said I should only store data in the
very 'tips' of the XML tree (i.e. not in intermediate branches). This
seems to rule out handling directory structures in the body of the tree.

Or should I use the directory names as 'tags' rather than data items in
the tree?
coding 'leg-work'? (i.e. directly transfer the directory structures
into XML)

Find a code example of walking a directory tree. Alter it to output XML.


Yes, I have found some code to handle this :-)

Thanks very much for your tips.

Regards,
Alan Searle.
Mar 2 '06 #10

P: n/a
Alan Searle wrote:
OK. But other contributers have said I should only store data in the
very 'tips' of the XML tree (i.e. not in intermediate branches).


Depends on what you're trying to do, and what you mean by "tip". I'd
suggest this is a perfect case for an attribute -- use something like
<directory name="whatever"> elements to build your directory tree
representation. (It could of course be done with a <name> child of the
<directory> element, but that wouldn't be as natural a way to express it
or manipulate it.)

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Mar 6 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.