On Wed, 30 Apr 2008 01:11:49 +0200, antrik wrote: > It could be possible though to pick one simple unambiguos XPath syntax > and use it for the static representation of the document contents... > That's why the task suggested considering the tree representation with a > view on both DOM *and* XPath. I'm not sure what is possible here (I know > very little about XPath), but it's certainly worth looking into.
DOM is a(n object) model for xml documents. In principle, using it or not is not the point. I think antrik wanted to say to translate the data model of the xml document to an directory structure so that the file _path_ resembles the [document structure][0] (PS: example, not puting extra nodes to amend the notation). When you use XSLT, you have to select nodes using XPath and learning it was vary easy to me because they followed the [principle of the least surpise][3] doing things as much compatible with unix directory naming convention as possible and using ortogonal concepts (see attribute selection as a node queried and as an expression) (PS: indeed, they are following their own recomendations about resource location). I mean: if we want an translator to create an unix directory tree that maps to data from an xml and back again, then we should (must?) use an convention that resembles xpath. Take this file named 'tom_sic.xml' (indented as a [MarkDown][] codeblock): <?xml version="1.0"?> <libraries xmlns:goudi='http://deux-fleurs.net/analyse-xmlfs' xmlns:pouet='http://deux-fleurs.net/analyse-xmlfs' > <pouet:library goudi:name="plop"> <curious_balise> </curious_balise> <!--a comment--> <book> <author>Mark Twain</author> <title>La case de l'oncle Tom</title> <isbn>4242</isbn> </book> <book /> Here is some CDATA <sub-library name="pikaplop"> <location>Grenoble</location> <name>Arlequin</name> </sub-library> CDATA, again ! </pouet:library> </libraries> I made some corrections on [Charly Caulet's example][4] (PS: a good examples, since it stresses the design). In portuguese, if you correct some quoting you must put "(sic)" before the correction. This (PS: unnecessary) comentary is just the unique prompt i think i will have to say to avoid saying "something et al." (meaning "something and all"). "Al." is abbreviation to "alumni". I know my english is bad. But if I do no correct, anybody won't correct me and I wont learn. See the following typescript: > xpath tom_sic.xml "/libraries/pouet:library/book[isbn = '4242']" Found 1 nodes: -- NODE -- <book> <author>Mark Twain</author> <title>La case de l'oncle Tom</title> <isbn>4242</isbn> </book> > xpath tom_sic.xml "/libraries/pouet:library/*[contains(name(),'ook')]" Found 2 nodes: -- NODE -- <book> <author>Mark Twain</author> <title>La case de l'oncle Tom</title> <isbn>4242</isbn> </book>-- NODE -- <book /> > A cople of days ago i played a little with this. The Perl module XML::Directory creates and xml representing an directory (lets bootstrap this shit!). Follows 'dir.pl': # refer to http://search.cpan.org/~pcimprich/XML-Directory-1.00/docs/Directory.pod use Data::Dumper; use XML::Directory::String;1 if (-d $ARGV[0]) { $dir = XML::Directory::String->new($ARGV[0]0,3,10) } else { print "usage: $0 dir\n"; exit }; $dir->set_details(1); $rc = $dir->parse_dir; @res = $dir->get_array; foreach $line (@res) { print "$line\n"; } A sample result is 'foo.xml': <?xml version="1.0" encoding="utf-8"?> <dirtree > <directory name="xml"> <file name=".dir.pl.swp"></file> <file name="dir.pl"></file> <file name="final.xml"></file> <file name="foo.pl"></file> <file name="foo.xml"></file> </directory> </dirtree> I made by hand, as a proof of concept, this directory tree: > find dirtree/ dirtree/ dirtree/directory dirtree/directory/directory dirtree/directory/directory/@name dirtree/directory/directory/[EMAIL PROTECTED] = 'foo.xml'] dirtree/directory/directory/[EMAIL PROTECTED] = 'foo.xml']/@name dirtree/directory/directory/[EMAIL PROTECTED] = 'dir.pl'] dirtree/directory/directory/[EMAIL PROTECTED] = 'dir.pl']/@name dirtree/directory/directory/[EMAIL PROTECTED] = 'foo.pl'] dirtree/directory/directory/[EMAIL PROTECTED] = 'foo.pl']/@name dirtree/directory/directory/[EMAIL PROTECTED] = '.dir.pl.swp'] dirtree/directory/directory/[EMAIL PROTECTED] = '.dir.pl.swp']/@name dirtree/directory/directory/[EMAIL PROTECTED] = 'perl5.8.8.core'] dirtree/directory/directory/[EMAIL PROTECTED] = 'perl5.8.8.core']/@name dirtree/directory/@name > find dirtree -type f -print0 | xargs -0 grep -v "notafilename" dirtree/directory/directory/@name:xml dirtree/directory/directory/[EMAIL PROTECTED] = 'foo.xml']/@name:foo.xml dirtree/directory/directory/[EMAIL PROTECTED] = 'dir.pl']/@name:dir.pl dirtree/directory/directory/[EMAIL PROTECTED] = 'foo.pl']/@name:foo.pl dirtree/directory/directory/[EMAIL PROTECTED] = '.dir.pl.swp']/@name:.dir.pl..swp dirtree/directory/directory/[EMAIL PROTECTED] = 'perl5.8.8.core']/@name:perl5.8.8.core dirtree/directory/@name:hurd > cat dirtree/directory/directory/[EMAIL PROTECTED] =\ \'*\]/@name .dir.pl.swp dir.pl foo.pl foo.xml perl5.8.8.core > That day, i realized some facts. had to try other possibilities but take this one just as a main part of the desired result. The interesting one is that, like the special file with name "*" from httpfs (that i could not use yet) which separates the local namespace and the foreing ("away", don't know, please correct) one, using "[" and "]" to enclose the conditional expression that selects nodes in a xpath, the XPath creators used the pattern of an array element qualified identifier from C language. May be if we do "ls dirtree/directory/directory/" we should get "@name file[]". This solves the problem of having more than one node. Well, is missing the order of the nodes and the commentary shit. "Special file" as the unix concept. Plan9 takes the "everthing is a file" paradigma. I don't know if this is our plan. In addition that, i don't understand Hurd concepts to talk about then properly. But if we will create an _unix_ diretory tree (with "/" as the relation symbol of the graph), we must think a directory as in unix. > hexdump xml/ 0000000 ee2f 0002 000c 0104 002e 0000 0026 0000 0000010 0024 0204 2e2e 0000 ee34 0002 0018 0c08 0000020 662e 6f6f 782e 6c6d 732e 7077 8900 cf64 0000030 ee32 0002 0010 0708 6f66 2e6f 6d78 006c 0000040 f029 0002 0020 0608 6f66 2e6f 6c70 cf00 0000050 ee35 0002 0010 0708 6964 2e72 6c70 007e 0000060 ee49 0002 0018 0608 6964 2e72 6c70 cf00 0000070 6964 2e72 6c70 cf00 ee47 0002 0014 0908 0000080 6966 616e 2e6c 6d78 006c c091 ee34 0002 0000090 0028 1c08 7473 7261 6974 676e 6e2e 746f 00000a0 6f73 7974 6570 6373 6972 7470 742e 7478 00000b0 f900 cf21 ee35 0002 014c 1408 6966 696e 00000c0 6873 6e69 2e67 7974 6570 6373 6972 7470 00000d0 1800 c06f 0000 0000 0000 0000 0000 0000 00000e0 0000 0000 0000 0000 0000 0000 0000 0000 * 0000200 > yeah! i am on an unix. It is not trivial to select an commentary with xpath (not to me). > xpath tom_sic.xml "/libraries/pouet:library/*[node()]" Found 3 nodes: -- NODE -- <curious_balise> </curious_balise>-- NODE -- <book> <author>Mark Twain</author> <title>La case de l'oncle Tom</title> <isbn>4242</isbn> </book>-- NODE -- <sub-library name="pikaplop"> <location>Grenoble</location> <name>Arlequin</name> </sub-library> > xpath tom_sic.xml "/libraries/pouet:library/*[comment()]" No nodes found > xpath tom_sic.xml "/libraries/pouet:library/*[commen()]" Can't locate object method "commen" via package "XML::XPath::Function" at /usr/local/lib/perl5/site_perl/5.8.8/XML/XPath/Function.pm line 69. > don't know what is happening. May be "comments" should go to [EMAIL PROTECTED] Diging further at [w3c recommendations][1] i found that comment() is for backward compatibility. > xpath tom_sic.xml "/libraries/pouet:library/*[not(comment())]" Found 4 nodes: -- NODE -- <curious_balise> </curious_balise>-- NODE -- <book> <author>Mark Twain</author> <title>La case de l'oncle Tom</title> <isbn>4242</isbn> </book>-- NODE -- <book />-- NODE -- <sub-library name="pikaplop"> <location>Grenoble</location> <name>Arlequin</name> </sub-library> > Nobody from w3c wants to select comment? Anybody here still wants to do so? (Anybody here still reading?) I don't. I mean to select comment. I doesn't make sense. Now i need to go back to the meaning of the file. To conclude. May be an comment is not an proper node. If Hurd New Generation needs comments, i will do so. I just seams that xpath ain't encoding the selection. I tested with the following implementations: > perl -e 'use XML::XPath qw(VERSION); print XML::XPath->VERSION . "\n"' 1.13 > sabcmd --version sabcmd 1.0.3 (June 26, 2006) copyright (C) 2000 - 2005 Ginger Alliance (www.gingerall.com) The Sablotron XSLT Processor comes with NO WARRANTY. It is subject to the Mozilla Public License Version 1.1. Alternatively, you may use Sablotron under the GNU General Public License. > When i did that directory tree, i had to decide that the "name" attribute of "directory" element "disambiguousate" (sorry the neologism usualy makes sence in portuguese, please correct me) (PS: makes univocal or unequivocal; makes not to call two or more things with the same name). We wont be using ad-hoc xml files. It must be valid following certain constraints. I used to think the XML document type declaration (thought the 'd' from DTD was "document") as an separated thing. Now i see it is an optional part of the same thing. If "curious#balise" can't be an name for an xml element, it can not be an name for a file on an xmlfs ("xml file system" as a concept, not as an implementation). Hence: > xmllint dir.xml --postvalid <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE dirtree [ <!ELEMENT directory (file | directory)*> <!ATTLIST directory name CDATA #REQUIRED> <!ELEMENT file EMPTY> <!ATTLIST file name CDATA #REQUIRED> ]> <dirtree> <directory name="xml"> <file name=".dir.pl.swp"/> <file name="dir.pl"/> <file/> <file name="foo.pl"/> <file name="foo.xml"/> </directory> </dirtree> dir.xml:8: element dirtree: validity error : No declaration for element dirtree dir.xml:12: element file: validity error : Element file does not carry attribute name Document dir.xml does not validate > ; wont setup an file system translator server. The `<!ELEMENT dirtree (directory)>` is missing and there is a file without name. Now, with a(n?) [well formed xml][2] "../dir.xml", perl -e 'use XML::Simple; $x = XMLin("../dir.xml"); sub md { $n = shift; print "mkdir -p $n->{name}; cd $n->{name}\n"; $g = $n->{file}; foreach $f (keys %$g) { print "touch $f\n" } $g = $x->{directory}; if (defined $n->{directory}) { md($n->{directory}) } print "cd ..\n" } md($x->{directory})' | sh will recreate (unserialize) the directory tree (certainly I will use XSLT the next time). I must say (again) that I don't want to put any kind of file inside an xml. Althought it looks like possible. (PS: actually the files aren't been serialized/unserialized) go for it, mf! This rugby is going down... -stty- References: [0]: http://www.w3.org/TR/xpath-datamodel/ "XQuery 1.0 and XPath 2.0 Data Model (XDM)", W3C Recommendation, 23 Jan. 2007. [1]: http://www.w3.org/TR/xpath-functions/ "XQuery 1.0 and XPath 2.0 Functions and Operators", W3C Recommendation, 23 Jan. 2007. [2]: http://www.w3.org/TR/REC-xml/#sec-well-formed "Extensible Markup Language (XML) 1.0. (Third Edition)", W3C Recommendation. [3]: http://en.wikipedia.org/wiki/Principle_of_least_astonishment [4]: http://deux-fleurs.net/analyse-xmlfs "La case de l'oncle Tom" [MarkDown]: http://daringfireball.net/projects/markdown/syntax "Daring Fireball: Markdown Syntax Documentation" PS: I like this task because it ... .... well i wont say. Just put it to eleven: Script started on Thu May 01 15:11:53 2008 (@TRIMMED@:~) @[EMAIL PROTECTED] /usr/sbin/svccfg -s apache2 svc:/network/http:apache2> listprop httpd application httpd/stability astring Evolving httpd/ssl boolean false network dependency network/entities fmri svc:/milestone/network:default network/grouping astring require_all network/restart_on astring error network/type astring service filesystem-local dependency filesystem-local/entities fmri svc:/system/filesystem/local:default filesystem-local/grouping astring require_all filesystem-local/restart_on astring none filesystem-local/type astring service autofs dependency autofs/entities fmri svc:/system/filesystem/autofs:default autofs/grouping astring optional_all autofs/restart_on astring error autofs/type astring service startd framework startd/ignore_error astring core,signal general framework general/enabled boolean true start method start/exec astring "/lib/svc/method/http-apache2 start" start/timeout_seconds count 60 start/type astring method stop method stop/exec astring "/lib/svc/method/http-apache2 stop" stop/timeout_seconds count 60 stop/type astring method refresh method refresh/exec astring "/lib/svc/method/http-apache2 refresh" refresh/timeout_seconds count 60 refresh/type astring method restarter framework NONPERSISTENT restarter/transient_contract count restarter/logfile astring /var/svc/log/network-http:apache2.log restarter/contract count 3909 restarter/start_pid count 24825 restarter/start_method_timestamp time 1209556078.609862000 restarter/start_method_waitstatus integer 0 restarter/auxiliary_state astring none restarter/next_state astring none restarter/state astring online restarter/state_timestamp time 1209556078.612699000 restarter_actions framework NONPERSISTENT restarter_actions/refresh integer restarter_actions/restart integer svc:/network/http:apache2> set prop general/enabled = false Usage: set [-vV] Without arguments, display current options. Otherwise set the given options. svc:/network/http:apache2> svc:/network/http:apache2> set prop general/enabled = falsprop general/enabled = false Permission denied. svc:/network/http:apache2> help General commands: help set repository end Manifest commands: inventory validate import export archive Profile commands: apply extract Entity commands: list select unselect add delete Snapshot commands: listsnap selectsnap revert Property group commands: listpg addpg delpg Property commands: listprop setprop delprop editprop Property value commands: addpropvalue delpropvalue setenv unsetenv svc:/network/http:apache2> help import Usage: import file Import a manifest into the repository. svc:/network/http:apache2> end (@TRIMMED@:~) @[EMAIL PROTECTED] man -k manifest bart_manifest bart_manifest (4) - system audit manifest file inetconv inetconv (1m) - convert inetd\&.conf entries into smf service manifests, import them into smf repository moe moe (1) - manifest the optimal expansion of a pathname service_bundle service_bundle (4) - service manifest file format (@TRIMMED@:~) @[EMAIL PROTECTED] man service_bundle Reformatting page. Please Wait... done File Formats service_bundle(4) NAME service_bundle - service manifest file format SYNOPSIS /usr/share/lib/xml/dtd/service_bundle.dtd.1 DESCRIPTION The service management facility, described in smf(5), util- izes an XML-based file format to marshal the description of a set of services or service instances between systems. This file is known as a service bundle. The primary form of a service bundle is the inventory of services that are pro- vided by a package, which is called a "service manifest". The DTD describing the service_bundle is provided at /usr/share/lib/xml/dtd/service_bundle.dtd.1. service_bundle documents can also use the XML Inclusions (XInclude) facil- ity to merge multiple documents into one. A service_bundle document manipulator must therefore support the functional- ity defined by the XInclude specification. A complete service description consists of the following: o A set of properties that identify the service and iden- tify its restarter o A set of properties that identify each instance o A set of framework property groups that describe the framework's understanding of each instance o A set of method property groups as required by svc.startd(1M), or by a delegated restarter o Additional optional method property groups o A set of dependency property groups o An optional group of properties that indicate services to which dependencies on the described service were --More--(34%) added o A set of application property groups or application- specific typed property groups containing application configuration data o A template that describes supporting information about this service, such as a description and links to docu- mentation. SunOS 5.10 Last change: 30 Aug 2004 1 File Formats service_bundle(4) The document type definition for the service bundle provides markup to define each of these aspects of a service descrip- tion, as well as a number of entities that identify regular features in describing a service, such as the <create_default_instance> tag. The attributes and tags are fully described in the commented DTD. The services supplied with the operating system, stored under /var/svc/manifest, provide examples of correctly formed service descriptions. Localization in the Template Element The description tags in the template element for a service are internationalizable. Service developers wishing to pro- vided localized descriptions of their services can elect to deliver a set of loctext element in the description, like <common_name> <loctext xml:lang="C">extended accounting<loctext> <loctext xml:lang="fr_CA">...</loctext> <loctext xml:lang="ja">...</loctext> .... </common_name> Alternatively, service developers can choose to deliver mul- tiple manifests in the naming scheme /var/svc/manifest/[category]/[service].[locale].xml --More--(69%) (@TRIMMED@:~) @[EMAIL PROTECTED] ls /var/svc/manifest application device milestone network platform site system (@TRIMMED@:~) @[EMAIL PROTECTED] ls /var/svc/manifestls /var/svc/manifest | grep apache2 /var/svc/manifest/network/http-apache2.xml (@TRIMMED@:~) @[EMAIL PROTECTED] cat /var/svc/manifest/network/http-apache2.xml <?xml version="1.0"?> <!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1"> <!-- Copyright 2006 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. ident "@(#)http-apache2.xml 1.3 06/03/27 SMI" --> <service_bundle type='manifest' name='SUNWapch2r:apache'> <service name='network/http' type='service' version='1'> <!-- Because we may have multiple instances of network/http provided by different implementations, we keep dependencies and methods within the instance. --> <instance name='apache2' enabled='false'> <!-- Wait for network interfaces to be initialized. --> <dependency name='network' grouping='require_all' restart_on='error' type='service'> <service_fmri value='svc:/milestone/network:default'/> </dependency> <!-- Wait for all local filesystems to be mounted. --> <dependency name='filesystem-local' grouping='require_all' restart_on='none' type='service'> <service_fmri value='svc:/system/filesystem/local:default'/> </dependency> <!-- Wait for automounting to be available, as we may be serving data from home directories or other remote filesystems. --> <dependency name='autofs' grouping='optional_all' restart_on='error' type='service'> <service_fmri value='svc:/system/filesystem/autofs:default'/> </dependency> <exec_method type='method' name='start' exec='/lib/svc/method/http-apache2 start' timeout_seconds='60' /> <exec_method type='method' name='stop' exec='/lib/svc/method/http-apache2 stop' timeout_seconds='60' /> <exec_method type='method' name='refresh' exec='/lib/svc/method/http-apache2 refresh' timeout_seconds='60' /> <property_group name='httpd' type='application'> <stability value='Evolving' /> <propval name='ssl' type='boolean' value='true' /> </property_group> <property_group name='startd' type='framework'> <!-- sub-process core dumps shouldn't restart session --> <propval name='ignore_error' type='astring' value='core,signal' /> </property_group> </instance> <stability value='Evolving' /> <template> <common_name> <loctext xml:lang='C'> Apache 2 HTTP server </loctext> </common_name> <documentation> <manpage title='httpd' section='8' manpath='/usr/apache2/man' /> <doc_link name='apache.org' uri='http://httpd.apache.org' /> </documentation> </template> </service> </service_bundle> (@TRIMMED@:~) @[EMAIL PROTECTED] /usr/sbin/svcadm refresh apache2 svcadm: svc:/network/http:apache2: Permission denied. (@TRIMMED@:~) @[EMAIL PROTECTED] /usr/sbin/svcadm refresh apach svcadm: svc:/network/http:apache2: Permission denied. (@TRIMMED@:~) @[EMAIL PROTECTED] /usr/sbin/s /usr/sbin/svcs: Command not found. (@TRIMMED@:~) @[EMAIL PROTECTED] /usr/ Usage: svcs [-aHpv] [-o col[,col ... ]] [-R restarter] [-sS col] [<service> ...] svcs -d | -D [-Hpv] [-o col[,col ... ]] [-sS col] [<service> ...] svcs -l <service> ... svcs -x [-v] [<service> ...] svcs -? (@TRIMMED@:~) @[EMAIL PROTECTED] /usr/bin/svcs -x svc:/network/http:apache2 (Apache 2 HTTP server) State: online since Wed Apr 30 08:47:58 2008 See: httpd(8) See: /var/svc/log/network-http:apache2.log Impact: None. (@TRIMMED@:~) @[EMAIL PROTECTED] /usr/bin/svcs - STATE STIME FMRI online Apr_30 svc:/network/http:apache2 16:30:35 1000 httpd 16:30:36 1002 httpd 16:30:37 1003 httpd 16:30:37 1005 httpd 16:30:37 1006 httpd 16:30:37 1007 httpd 17:12:37 1334 httpd 17:15:19 1371 httpd Apr_30 24831 httpd Apr_30 24836 httpd Apr_30 25394 httpd (@TRIMMED@:~) @[EMAIL PROTECTED] uname -a SunOS @TRIMMED@ 5.10 Generic_120012-14 i86pc i386 i86pc (@TRIMMED@:~) @[EMAIL PROTECTED] exit script done on Thu May 01 15:20:22 2008 Abra sua conta no Yahoo! Mail, o único sem limite de espaço para armazenamento! http://br.mail.yahoo.com/