Directory Scanning

A

Alan Searle

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.
 
F

fedro

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
 
T

Tjerk Wolterink

fedro said:
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.
 
A

Andy Dingley

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".
 
F

fedro

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
 
A

Alan Searle

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.
 
A

Andy Dingley

Alan said:
<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.
 
J

Joe Kesselman

Alan said:
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.
 
A

Alan Searle

Hi Joe,
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?
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.
 
J

Joe Kesselman

Alan said:
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.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top