lunedì 15 giugno 2009

FsGateway: looking inside an XML file as a filesystem.

FsGateway is a Mono application that allow to mount several entity as a filesystem. To do this one mono-fuse is used. Actually when you need to start the fsgateway you need do specify the filesystem type and the mountpoint. Now will describe the use of xmlfs "module". This module allow to mount a XML file into the normal filesystem. To do this simply run the application specify filesystem type (xmlfs), an XML file (in this case ~/mono_sugar/xml/xml/xml/bin/Debug/test3.xml) and the mountpoint (in this case mountpoint/):
mono fsgateway.exe xmlfs ~/mono_sugar/xml/xml/xml/bin/Debug/test3.xml mountpoint/
Now you can use your preferred file manager like nautilus or dolphin to see the content and open each node like a file: If you run the "find" or "grep" utilities, the file name that you get contains the XPath query to access the node. For example:
find mountpoint -iname "*md5*"
give this result for the file that I specify:
mountpoint/def:metadigit/def:img[1]/def:md5 mountpoint/def:metadigit/def:img[1]/def:altimg[1]/def:md5 mountpoint/def:metadigit/def:img[1]/def:altimg[2]/def:md5 mountpoint/def:metadigit/def:img[2]/def:md5 mountpoint/def:metadigit/def:img[2]/def:altimg[1]/def:md5 mountpoint/def:metadigit/def:img[2]/def:altimg[2]/def:md5 mountpoint/def:metadigit/def:img[3]/def:md5 mountpoint/def:metadigit/def:img[3]/def:altimg[1]/def:md5 mountpoint/def:metadigit/def:img[3]/def:altimg[2]/def:md5 mountpoint/def:metadigit/def:img[4]/def:md5 mountpoint/def:metadigit/def:img[4]/def:altimg[1]/def:md5 mountpoint/def:metadigit/def:img[4]/def:altimg[2]/def:md5 mountpoint/def:metadigit/def:img[5]/def:md5 mountpoint/def:metadigit/def:img[5]/def:altimg[1]/def:md5 mountpoint/def:metadigit/def:img[5]/def:altimg[2]/def:md5 mountpoint/def:metadigit/def:img[6]/def:md5 mountpoint/def:metadigit/def:img[6]/def:altimg[1]/def:md5 mountpoint/def:metadigit/def:img[6]/def:altimg[2]/def:md5 mountpoint/def:metadigit/def:img[7]/def:md5 mountpoint/def:metadigit/def:img[7]/def:altimg[1]/def:md5 mountpoint/def:metadigit/def:img[7]/def:altimg[2]/def:md5 mountpoint/def:metadigit/def:img[8]/def:md5 mountpoint/def:metadigit/def:img[8]/def:altimg[1]/def:md5 mountpoint/def:metadigit/def:img[8]/def:altimg[2]/def:md5
The same way, if you run "grep" you get the same behavior. For example:
grep -ril piccolo mountpoint/
gives as result:
mountpoint/def:metadigit/def:bib/dc:description/text()
You can find the source code here. Note: the def prefix is automatically added by the module for the default namespace. If this prefix is already used, the module use def2, or def3 ... and so on.