[web-devel] DTD types

John Millikin jmillikin at gmail.com
Wed Jun 1 01:01:26 CEST 2011


On Tue, May 31, 2011 at 00:30, Yitzchak Gale <gale at sefer.org> wrote:
>>> For example, I couldn't use name, because for DTD namespaces
>>> *are* significant so they need a different Eq instance. I ended up
>>> just using Text."
>
>> I don't understand what this means; the xml-types Eq instance
>> for Name compares both the namespace and local name
>
> Ah, OK. I misunderstood the docs - it says that the "prefix"
> is not used in the Eq instance, so I took that to mean
> that namespaces prefixes were not used. Now that I look
> more carefully at the code itself, I see that is not true.
>
> But then what is a "prefix"? The IsString instance always sets
> the prefix to Nothing. I've scoured the XML spec and not
> found anything it could possibly represent. What have I
> missed?

Lets say you have a document like this:

<foo:doc xmlns:foo="http://my/namespace/here">bar</foo:doc>

The name of the element will have the components:

prefix = "foo"
namespace = "http://my/namespace/here"
local name = "doc"

The prefix is not semantically important; all names are identified by
the (namespace, local name) pair. Thus, comparing two names ignores
the prefix. But it's still useful to keep around when 1) working with
poorly-written parsers (eg, many XMPP servers) or 2) performing
minimal-diff changes on a complex document.

> Another point I noticed when looking at the IsString instance
> for Name: it can introduce crashes into a program if someone
> accidentally puts a '{' at the beginning of a Name string.
> Everywhere else, your code is safe; even if someone inserts
> invalid XML, you leave it up to the application to decide
> how much to validate and what to do if validation fails.
>
> So could you please change this to pass the string through
> as a plain Name without a namespace if Clark notation
> parsing fails? Thanks.

The IsString instance is intended for overloaded string literals --
that is, the source code would look something like this:

------------------
elem = Element "{http://my/namespace/here}doc" [] []
------------------

It's not intended for parsing arbitrary input, as it performs no
validation of its input (aside from trivial checks for Clark
brackets).

If you are concerned that a developer may cause exceptions by writing
incorrect code, it would be better to use the Name constructor
directly.

> I noticed that you did not send your response to the list.
> Do you mind if I forward a copy of this response
> to the web-devel list?

Oops, didn't realize there were two separate email threads. Here's the
text of my earlier email, for future readers:

----------------
On Mon, May 30, 2011 at 11:13, John Millikin <jmillikin at gmail.com> wrote:
> I agree that it makes more sense as a separate package -- DTDs are
> sort of a layer on top of XML, and there's lots of people who want to
> work with one without worrying about the other. I don't mind merging
> them if you want, but separate seems better.
>
>> For example, I couldn't use name, because for DTD namespaces *are* significant so they
>> need a different Eq instance. I ended up just using Text."
>
> I don't understand what this means; the xml-types Eq instance for Name
> compares both the namespace and local name:
>
> --------------------------------
> instance Eq Name where
>        (==) = (==) `on` (\x -> (nameNamespace x, nameLocalName x))
> --------------------------------
>
> As to the package itself, I have only one suggestion: can you add a
> constructor to DTDComponent for processing instructions? If I'm
> reading the XML spec correctly, these can occur anywhere within a DTD.
>
> Thank you very much for the good work!
----------------



More information about the web-devel mailing list