Erlang Mailing Lists

Author Message

<  User Contributions  ~  erlsom 1.0.0

Willem
Posted: Tue May 22, 2007 7:14 pm Reply with quote
User Joined: 21 Jul 2006 Posts: 59
I have released a new version of erlsom.

What is Erlsom?
Erlsom is an 'XML data binder' (see http://en.wikipedia.org/wiki/XML_data_binding). Quoting from the Wikipedia article:

Quote:
"XML data binding refers to the process of representing the information in an XML document as an object in computer memory. This allows applications to access the data in the XML from the object rather than using the DOM to retrieve the data from a direct representation of the XML itself.

An XML data binder accomplishes this by creating a mapping between elements of the XML schema of the document we wish to bind and members of a class to be represented in memory.

When this process is applied to convert an XML document to an object, it is called unmarshalling. The reverse process, to serialize an object as XML, is called marshalling."


An example of an 'XML binder' for Java is JAXB, see http://java.sun.com/developer/technicalArticles/WebServices/jaxb/ for some pictures that look remarkably similar to the picture in the Erlang documentation.

So how does this translate to the Erlang world? Erlsom is a set of functions to deal with XML Schema (XSDs) in Erlang. First you 'compile' the schema, and after that you can parse XML documents that conform to the schema. The result is a structure of Erlang records, based on the types that are defined by the Schema. Or, the other way around, a structure of records can be translated to an XML document.

As an example, after compiling the XSD (not shown here), the following XML document:
Code:
<?xml version="1.0"?>
<BookStore xmlns="http://www.books.org">
        <Book>
                <Title>My Life and Times</Title>
                <Author>Paul McCartney</Author>
                <Date>1998</Date>
                <ISBN>1-56592-235-2</ISBN>
                <Publisher>McMillin</Publisher>
        </Book>
        <Book>
                <Title>The Adventures</Title>
                <Author>Richard Bach</Author>
                <Date>1977</Date>
                <ISBN>0-440-34319-4</ISBN>
                <Publisher>Dell</Publisher>
        </Book>
</BookStore>


will be translated to:
Code:
{'BookStore',[],
             [{'Book',[],
                      "My Life and Times",
                      "Paul McCartney",
                      "1998",
                      "1-56592-235-2",
                      "McMillin"},
              {'Book',[],
                      "The Adventures",
                      "Richard Bach",
                      "1977",
                      "0-440-34319-4",
                      "Dell"}]}


If you want, you can let erlsom create record definitions (from the XSD). In that case the translated XML could be printed as:
Code:
#'BookStore'{anyAttribs = [],
             'Book' = [#'Book'{anyAttribs = [],
                      'Title' = "My Life and Times",
                      'Author' = "Paul McCartney",
                      'Date' = "1998",
                      'ISBN' = "1-56592-235-2",
                      'Publisher' = "McMillin"},
              #'Book'{anyAttribs = [],
                      'Title' = "The Adventures",
                      'Author' = "Richard Bach",
                      'Date' = "1977",
                      'ISBN' = "0-440-34319-4",
                      'Publisher' = "Dell"}]}



What is new in version 1.0.0?
- Lots of bug fixes
- Decoding of iso-8859-1 encoded documents
- Erlsom:scan() replaces erlsom:parse(). It returns an additional value: the remaining characters in the input after the last closing tag of the XML document
- The restrictions that existed on the use of 'mixed' types no longer exist
- Substitution groups are supported
- Redefine is supported
- Support for abstract types has been improved. xsi:type is now used to determine the type.
- Additional prefixes can be specified for elements, groups, types in order to avoid name clashes
- Parsing an XML document does not create new atoms any more (the atoms are created at the time the XSD is compiled, no new atoms are created while paring, not even if the XML contains unexpected tags)

How does erlsom compare to xmerl?
The standard OTP distribution includes an XML parser called xmerl, which works fine. When can it be more convenient or appropriate to use erlsom? And when will erlsom definitely not be of any use?

My suggestion is that you should consider erlsom if:
- the xml documents that you are parsing (or writing) follow a clear pattern or grammar that is known in advance and can be described by an XML schema. You may already have a schema (XSD), but if not it should generally not be very difficult to produce one.
- you want the parsing to be fast and efficient (or at least faster than xmerl)
- you want to get the output of the parser in a format that is compact and convenient
- you want to be sure that no atoms are created during parsing (creating too many atoms is a potential problem since they are not garbage collected)
- if you want to use the soap support offered by yaws

Using erlsom could be less appropriate (or even impossible) if:
- the xml can have any arbitrary format, or if you are not able to create an XSD
- if you want to use some of the additional tools or options that come with xmerl, such as xmerl_xs and xmerl_xpath
- if the support and security offered by the fact that xmerl is part of OTP are important to you


How to get and install the code
You can find the erlsom code on sourceforge. There are two ways:

A.download the file from http://sourceforge.net/projects/erlsom, unzip it in the right location, compile the files.
This is explained in a little more detail in the documentation.

B. get the file from cvs:
Code:
cvs -d:pserver:anonymous@erlsom.cvs.sourceforge.net:/cvsroot/erlsom login
cvs -z3 -d:pserver:anonymous@erlsom.cvs.sourceforge.net:/cvsroot/erlsom co -P erlsom
cd erlsom; ./configure; make

note:
1. <at> should be replaced by the <at> sign;
2. this are 3 lines - the first 2 start with cvs, the last one starts with cd.
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum