[Haskell] HaXML incorrect interpretation of XML spec!

Graham Klyne GK at ninebynine.org
Thu Oct 28 07:55:06 EDT 2004


Looking at the before-and-after versions of HaXml code that I have modified 
[1] (with the primary goal of adding namespace support, but also numerous 
other changes), it seems that the parser always allowed PIs to appear 
before and after the DTD, but did not store them in the resulting data 
structure.  (That is still the situation with my code.)

Here's the original code for the prolog parser that I have:
[[
prolog :: XParser Prolog
prolog = do
     x <- maybe xmldecl
     many misc
     dtd <- maybe doctypedecl
     many misc
     return (Prolog x dtd)
]]

It's clear from this that the PIs (and comments) are parsed and discarded, 
so your change to capture these in the prolog makes sense.

#g
--

[1] http://www.ninebynine.org/Software/HaskellUtils/HaXml-1.12/
(My modified version.)

At 00:44 28/10/04 -0400, S. Alexander Jacobson wrote:
>I modified the Prolog type to be
>
>    data Prolog = Prolog (Maybe XMLDecl) [Misc] (Maybe DocTypeDecl) [Misc]
>
>and then modified the Prolog parser (which
>actually was correct) to actually use the misc
>values in constucting the Prolog.  I replace the
>prolog function in pretty.hs with
>
>    prolog (Prolog x m1 dtd m2) = maybe xmldecl x $$
>                                 vcat (map misc m1) $$
>                                 maybe doctypedecl dtd $$
>                                 vcat (map misc m2)
>
>and did a few more similar things in
>Haskell2XML and XML2Haskell (about a 5 min
>operation) and it all seems to work properly.
>
>Implementation question: Why is there so much
>replicated code in HaXML/Html (parse.hs and
>pretty.hs)
>
>Given that this fix was so very easy and given
>that the parser was already spec consistent, I now
>have to assume that there was good reason for the
>Prolog to be spec inconsistent, but I don't know
>what it is...
>
>Thoughts?
>
>-Alex-
>
>
>
>
>On Wed, 27 Oct 2004, S. Alexander Jacobson wrote:
>
> > The XML spec defines the prolog(1) as follows:
> >
> >   [22]        prolog     ::=          XMLDecl? Misc* (doctypedecl Misc*)?
> >
> > In other words you can have Misc before AND after
> > the doctype declaration!
> >
> > HaXml defines the prolog(2) as:
> >
> >   data Prolog = Prolog (Maybe XMLDecl) (Maybe DocTypeDecl)
> >
> > HaXml therefore does not allow PIs before the
> > beginning of the top level element.  This is a
> > problem in practice for people who want to use
> > e.g. XML-Stylesheets(3) where if one is using XSL
> > to produce HTML it is necessary to put
> > the stylesheet declaration BEFORE the root element
> > (if the root element is not HTML).  e.g.
> >
> >   <?xml version="1.0"?>
> >   <?xml:stylesheet type="text/xsl" href="style.xsl"?>
> >   <foo id="57" category="2"/>
> >
> > Is there some way to puta PI before the
> > root element in combinators?
> >
> > -Alex-
> >
> > (1) http://www.w3.org/TR/REC-xml/#sec-prolog-dtd
> > (2) 
> http://www.cs.york.ac.uk/fp/HaXml/HaXml/Text.XML.HaXml.Types.html#Prolog
> > (3) http://www.w3.org/TR/xml-stylesheet/
> > ______________________________________________________________
> > S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com
> > _______________________________________________
> > Haskell mailing list
> > Haskell at haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell
> >
>
>______________________________________________________________
>S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com
>_______________________________________________
>Haskell mailing list
>Haskell at haskell.org
>http://www.haskell.org/mailman/listinfo/haskell

------------
Graham Klyne
For email:
http://www.ninebynine.org/#Contact



More information about the Haskell mailing list