Let’s take a bottom-up approach to analyzing types. This section will also serve as a primer on the XML data model itself, so don’t worry if you’re not completely familiar with it.
I think the first place where Haskell really shows its strength is with the
Name data type. Many languages (like Java) struggle with
properly expressing names. The issue is that there are in fact three components to a
name: its local name, its namespace (optional), and its prefix (also optional). Let’s
look at some XML to explain:
<no-namespace/> <no-prefix xmlns="first-namespace" first-attr="value1"/> <foo:with-prefix xmlns:foo="second-namespace" foo:second-attr="value2"/>
The first tag has a local name of
no-namespace, and no
namespace or prefix. The second tag (local name:
no-prefix) also has no prefix, but it does have a namespace (
first-attr, however, does not
inherit that namespace: attribute namespaces must always be explicitly set with a prefix.
Namespaces are almost always URIs of some sort, though there is nothing in any specification requiring that it be so.
The third tag has a local name of
with-prefix, a prefix of
foo and a namespace of
Its attribute has a
second-attr local name and the same prefix and namespace.
xmlns:foo attributes are part of the namespace
specification, and are not considered attributes of their respective elements.
So let’s review what we need from a name: every name has a local name, and it can optionally have a ...