English 中文(简体)
An XML language for describing file attributes of a directory tree?
原标题:

I have an application in mind which will record directory listings of a file system in text form. That is, it should say something like:

File name is: abc.txt
Last modification date is: 2009-12-31T01:23
Read-only attribute is: True
Hidden attribute is: False

The listings will persist for years in a long-term archive, so the language should be self-evident to an information archaeologist of the future. The language should be able to describe the most commonly-used file attributes of common PC platform file systems: NTFS, FAT, HFS+, ext2/3, etc. It should be able to handle non-Latin file names, different semantics for time stamps on different file systems, etc.

Of course, the obvious choice of a language for structuring this data is some XML-based language. Can anyone point me to a language which already exists for describing hierarchical structures of file attributes and directory attributes, as in a file system? I m hoping to benefit from the work those language designers did to get the semantics right, create the schema or DTD, work out the niggling details of whether something should be an XML element or attribute, etc.

I ve looked in the obvious places: http://xml.coverpages.com, web search engines, the archives of XML-L and comp.text.xml, and here. I didn t find any traces of such languages. The search was complicated a bit because the search term "file attributes" gets lots of hits on the term attributes as used in XML.

Please suggest languages I should investigate. It helps to have the name of the language, and a pointer to a URL where the language and its related tools, syntax definitions, etc. are described.

Thanks in advance!

问题回答

Tree size is using an XML format to describe directory and file trees.

David A Lee from the XML-Dev list replied:

The xls command in xmlsh does exactly this, but I wouldnt consider it a format designed for long term archival use. It might be useful to you or it might not

http://www.xmlsh.org

Example output

xls -l


<dir>
 <file name="README.txt" path="C:/Work/DEI/xmlsh/trunk/README.txt" length="191" type="file" readable="true" writable="true" executable="true" mtime="2008-11-10T11:18:59"/>
 <file name="_dist" path="C:/Work/DEI/xmlsh/trunk/_dist" length="0" type="dir" readable="true" writable="true" executable="true" mtime="2009-11-23T10:38:00"/>
 <file name="_out" path="C:/Work/DEI/xmlsh/trunk/_out" length="0" type="dir" readable="true" writable="true" executable="true" mtime="2009-11-23T10:38:04"/>
 <file name="bin" path="C:/Work/DEI/xmlsh/trunk/bin" length="0" type="dir" readable="true" writable="true" executable="true" mtime="2009-11-23T10:26:06"/>
 <file name="build-lib" path="C:/Work/DEI/xmlsh/trunk/build-lib" length="0" type="dir" readable="true" writable="true" executable="true" mtime="2009-11-01T11:57:19"/>
 <file name="build.xml" path="C:/Work/DEI/xmlsh/trunk/build.xml" length="3732" type="file" readable="true" writable="true" executable="true" mtime="2009-11-14T12:31:37"/>
 <file name="doc" path="C:/Work/DEI/xmlsh/trunk/doc" length="0" type="dir" readable="true" writable="true" executable="true" mtime="2009-11-01T11:56:17"/>
 <file name="lib" path="C:/Work/DEI/xmlsh/trunk/lib" length="0" type="dir" readable="true" writable="true" executable="true" mtime="2009-11-20T07:56:56"/>
 <file name="license.txt" path="C:/Work/DEI/xmlsh/trunk/license.txt" length="1540" type="file" readable="true" writable="true" executable="true" mtime="2009-04-09T09:15:50"/>
 <file name="notices" path="C:/Work/DEI/xmlsh/trunk/notices" length="0" type="dir" readable="true" writable="true" executable="true" mtime="2009-11-20T07:49:36"/>
 <file name="out.txt" path="C:/Work/DEI/xmlsh/trunk/out.txt" length="0" type="file" readable="true" writable="true" executable="true" mtime="2009-11-23T20:44:33"/>
 <file name="samples" path="C:/Work/DEI/xmlsh/trunk/samples" length="0" type="dir" readable="true" writable="true" executable="true" mtime="2009-05-27T11:36:54"/>
 <file name="schemas" path="C:/Work/DEI/xmlsh/trunk/schemas" length="0" type="dir" readable="true" writable="true" executable="true" mtime="2008-05-26T20:36:41"/>
 <file name="sh_histo" path="C:/Work/DEI/xmlsh/trunk/sh_histo" length="23" type="file" readable="true" writable="true" executable="true" mtime="2009-11-23T11:02:38"/>
 <file name="src" path="C:/Work/DEI/xmlsh/trunk/src" length="0" type="dir" readable="true" writable="true" executable="true" mtime="2009-03-20T10:21:07"/>
 <file name="test" path="C:/Work/DEI/xmlsh/trunk/test" length="0" type="dir" readable="true" writable="true" executable="true" mtime="2009-10-29T11:14:29"/>
 <file name="unix" path="C:/Work/DEI/xmlsh/trunk/unix" length="0" type="dir" readable="true" writable="true" executable="true" mtime="2009-11-16T15:17:48"/>
 <file name="win32" path="C:/Work/DEI/xmlsh/trunk/win32" length="0" type="dir" readable="true" writable="true" executable="true" mtime="2009-09-20T07:54:55"/>
 <file name="xmlsh.log" path="C:/Work/DEI/xmlsh/trunk/xmlsh.log" length="116538" type="file" readable="true" writable="true" executable="true" mtime="2009-11-23T20:44:31"/>
</dir>

Peter Flynn on the XML-L list kindly pointed me to Cocoon. I found the Directory Generator in Cocoon: http://cocoon.apache.org/2.1/userdocs/directory-generator.html

It generates XML directory listings according to a DTD they show there, but here s an example:

<dir:directory xmlns:dir="http://apache.org/cocoon/directory/2.0"
    name="stylesheets" lastModified="1056668768203" date="27.06.03 01:06" size="0"
    requested="true" sort="name" reverse="false">
  <dir:directory name="sites" lastModified="1056668768203" date="27.06.03 01:06" size="0"/>
  <dir:file name="dynamic-page2html.xsl" lastModified="1056668768203" date="27.06.03 01:06" size="4321"/>
  <dir:file name="simple-xml2html.xslt" lastModified="1056668768203" date="27.06.03 01:06" size="1234"/>
</dir:directory>

There is also an XPath Directory Generator: cocoon.apache.org/2.1/userdocs/xpathdirectory-generator.html

Their summary is, "The XPath Directory Generator provides all the functionality of the Directory Generator. Additionaly it is possible to get XML snippets out of the XML files the Directory Generator finds." It generates directory listings like the following example:

<dir:directory xmlns:dir="http://apache.org/cocoon/directory/2.0"
    name="articles" lastModified="1057183738609" date="03.07.03 00:08" size="0"
    requested="true" sort="name" reverse="false">
  <dir:directory name="images" lastModified="1057183738609" date="03.07.03 00:08" size="0"/>
  <dir:file name="article1.xml" lastModified="1057183738609" date="03.07.03 00:08" size="123">
    <dir:xpath query="/article/title">
      <title>My first article!</title>
    </dir:xpath>
  </dir:file>
  <dir:file name="article2.html" lastModified="1057183738609" date="03.07.03 00:08" size="345"/>
  <dir:file name="article2.xml" lastModified="1057183738609" date="03.07.03 00:08" size="234">
    <dir:xpath query="/article/title">
      <title>My second article!</title>
    </dir:xpath>
  </dir:file>
</dir:directory>

What I find interesting about this language is that they put all the file attributes in XML entity attributes, rather than between the tags. I m very naive on XML language design, so I don t know the pros and cons of each approach. But that s exactly why I hope to piggyback on someone else s language design.





相关问题
how to represent it in dtd?

I have two element action and guid. guid is a required field when action is add. but when action is del it will not appear in file. How to represent this in dtd ?

.Net application configuration add xml-data

I need to add xml-content to my application configuration file. Is there a way to add it directly to the appSettings section or do I need to implement a configSection? Is it possible to add the xml ...

XStream serializing collections

I have a class structure that I would like to serialize with Xstream. The root class contains a collection of other objects (of varying types). I would like to only serialize part of the objects that ...

MS Word splits words in its XML format

I have a Word 2003 document saved as a XML in WordProcessingML format. It contains few placeholders which will be dynamically replaced by an appropriate content. But, the problem is that Word ...

Merging an XML file with a list of changes

I have two XML files that are generated by another application I have no control over. The first is a settings file, and the second is a list of changes that should be applied to the first. Main ...

How do I check if a node has no siblings?

I have a org.w3c.dom.Node object. I would like to see if it has any other siblings. Here s what I have tried: Node sibling = node.getNextSibling(); if(sibling == null) return true; else ...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

热门标签