XML Shell

Carlo Contavalli <ccontavalli at commedia.it> Thu May 1 17:34:37 CEST 2003

This file documents a patch I’ve made for courier to allow automatic maildir creation. This manual, the mentioned patch and all the provided files are copyright \begin{matrix}c \\ ◯ \end{matrix} Carlo Contavalli 2001-2003. Please read the following sections for more details. Note that this is free software and authors hold no responsibility for any damage or loss, direct or indirect, caused by using this software. Use it only on your OWN risk and AFTER carefully reading this documentation. The latest version of this document can be found

at http://www.commedia.it/ccontavalli/ .

1 License, copyright and...

This document was written by Carlo Contavalli <ccontavalli at commedia.it> and is thus Copyright \begin{matrix}c \\ ◯ \end{matrix} Carlo Contavalli 2001-2002.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts.

Any example of program code available in this document should be considered protected by the terms of the GNU General Public License.

The software to which this document refers to is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

The software this document refers to is distributed in the hope that it will be useful, but WITHOUT ANY WAR-RANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PUR-POSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

Trademarks are owned by their respective owners.

2 About this document

Ok, simple as it is, I needed to have a bash script driven by a xml file...

At the time, I didn’t know about pyxie or that nsgmls gives a nice output that can be easily used, so I ended up taking “xml2” by Dan Egnor from the Debian archive, stripping down most of the lines and adding a bounce of them just to get “xml-sh”.

xml-sh is just a small C program that given an xml file on standard input (using < redirection), it generates on standard output something like the following:

     E        html
     E        head
     E        title
     T        This is the title
     L        title
     E        meta

     A        http-equiv       content-type
     A        content text/html; charset=ISO-8859-1
     L        meta
     L        head
     [...]

easy to read from a bash script with something like:

     while read type name value; do
        case $type in
              A)
                ;;
              E)
                ;;
              L)
                ;;
              T)
                ;;
     done;

As you may guess, “E” means a tag was entered, “L” that it was left, “A” means an attribute was found, and “T” is followed by the text enclosed by an opening and a closing tag, with spaces stripped down to “ ”.

Each argument is separated by a “tab”, so you can use a simple “read”...

You can also specify the “-c” option, in which case xml-sh will also print the nesting level the tag was found in. This is useful for skipping all the tags between one opening and closing tags. For example, the following xml:

     <test>
        <test>
          <test>
            This is a test   look      how
            spaces are handled
          </test>
        </test>
     </test>

would generate the following “xml-sh -c” output:

     E        1        test
     E        2        test
     E        3        test
     T        3        This is a test look how spaces are handled
     L        3        test
     L        2        test
     L        1        test

3 Installation

You need:

• A POSIX C compiler, a POSIX system and any kind of make

• libxml 1 installed somewhere on your system, complete of the headers (in Debian, install libxml-dev)

• the script “xml-config” somewhere in your path After decompressing the tarball with something like

        gzip -cd xml-sh.tar.gz |tar xv

just cd into xml-sh and run make.

        $ cd xml-sh
        $ make

and you should be done. Now, you can simply copy the file xml-sh wherever you prefer. Keep in mind that xml-sh is really simple... you shouldn’t have any problem compiling it once all the prerequisites are satisfied. It actually took me longer to write this document than to hack xml-sh. Have fun!