Overview

This is a binding of expat to the LambdaMOO Server (currently at version 1.8.1). It provides two new functions which accept an XML document in a string, parse it using expat, and return a LIST data structure representing the parsed XML. It was written by Ken Fox.

Download

ext-xml.README
The expat binding readme, which documents the two new functions and has installation instructions. It also includes the license info for this patch.
ext-xml-1.0.tar.gz
The ext-xml distribution. You'll also need the expat distribution. Many Linux and BSD distributions have the expat library available as a package. For example, in debian it's called libexpat1 and the headers are in libexpat1-dev. You'll need both packages if you're using Debian.

Use

Once this patch is installed, the MOO server has two new builtins:

Both return a list of the form:
   {STR tag, LIST attributes alist, STR text, LIST children}
STR tag
tag name
LIST attributes
alist of attributes {{STR key, STR value}, ...}
STR text
text between the tags
LIST children
children of this node

The difference between xml_parse_tree and xml_parse_document lies in where text between tags ends up. xml_parse_tree puts it all in the "text" element of the node. xml_parse_document puts it in the children element. This may be clearer with examples. The indendation of the return values is for illustrative purposes only.

;xml_parse_tree("<XML>abc</XML>") 
=> {{"XML",        -- tag name
     {},           -- attribute alist 
     "abc",        -- text
     {}}}          -- children
;xml_parse_tree("<list><item>foo</item><item>bar</item></list>") 
=> {{"list",       -- tag name of root
     {},           -- attributes
     "",           -- text
     {{"item",     -- tag name of first child
       {},         -- attributes of first child 
       "foo",      -- text of first child
       {}          -- children of first child 
      },         
      {"item",     -- tag name of second child
       {},         -- attributes of second child
       "bar",      -- text of second child
       {}          -- children of second child
      }           
     }             -- end of children of root
    }
   }
;xml_parse_document("<document coolness=\"yes\">The <EM>brown cow</EM> " +
                    "lept over " +
                    "the <EM>blue moon</EM></document>") 
=> {"document",
    {{"coolness", "yes"}},
    "",
    {"The ",
     {"EM", {}, "", {"brown cow"}}
     "lept over ",
     {"EM", {}, "", {"blue moon"}}
    }}

License

Copyright 2000 by Ken Fox.

Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation.

KEN FOX DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL KEN FOX BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.