XML Schema support

Willem de Jong w.a.de.jong@REDACTED
Tue Jan 10 21:33:53 CET 2006


I have written a set of functions to deal with XML Schemas in Erlang. First you
compile an XSD, and after that you can parse an XML document that conforms
to the XSD. The result is an Erlang structure.

I'll tell a little bit more about the functionality below, but the
main point of this
mail is to get some advice/input. I have no experience with open
source software
development, and I have no experience with Erlang besides these
modules. My plan was to write a small program to find out a bit more
about Erlang, but it got
out of hand somewhat.

As I said, I would welcome your feedback:
- do you think this might be of use
- if so, what would I need to make sure that it can really be used?
- what would be the best way to publish it?

The idea is probably best explained by an example. I am sorry if it is a bit
long -  XML documents in general are sort of long, and this is certainly true
for XSDs.

If XSD =
  <schema xmlns="http://www.w3.org/2001/XMLSchema"
    <element name="purchaseOrder" type="po:PurchaseOrderType"/>
    <element name="comment"       type="string"/>
    <complexType name="PurchaseOrderType">
        <element name="shipTo"    type="po:USAddress"/>
        <element name="billTo"    type="po:USAddress"/>
        <element ref="po:comment" minOccurs="0"/>
      <attribute name="orderDate" type="date"/>
    <complexType name="USAddress">
        <element name="name"   type="string"/>
        <element name="street" type="string"/>
      <attribute name="country" type="NMTOKEN"/>

and XML =
  <?xml version="1.0"?>
  <apo:purchaseOrder xmlns:apo="http://www.example.com/PO1"
    <apo:shipTo country="US">
      <apo:name>Alice Smith</apo:name>
      <apo:street>123 Maple Street</apo:street>
    <apo:billTo country="US">
      <apo:name>Robert Smith</apo:name>
      <apo:street>8 Oak Avenue</apo:street>
    <apo:comment>Hurry, my lawn is going wild</apo:comment>

Then executing:
Model = erlSom:compile(XSD, {"b", "http://www.example.com/PO1"}),
erlSom:parse(XML, Model).

Will give you:
                       {'b:USAddress',"US","Alice Smith","123 Maple Street"},
                       {'b:USAddress',"US","Robert Smith","8 Oak Avenue"},
                       "Hurry, my lawn is going wild"}

The parser supports the most essential elements of the XML Schema spec, such
as: element, simple type, complex type, namespaces, attributes, minOccurs,
maxOccurs, choice, element groups and 'any' (in a limited sense: the elements
are simply ignored).

There are also many things it doesn't support right now. Most important
is probably that it doesn't support 'import': the XSD has to be in one
file (and can, therfore, cover only 1 namespace). Besides that, there is
also no support for: all, mixed, attributeGroup, facets, redefine, extension,
restriction etc.


More information about the erlang-questions mailing list