Hi Daniel,

Thanks for your bugreport. I am CC'ing Malcolm so he can give input as
well.

Op zo, 06-08-2006 te 16:57 -0400, schreef Daniel Burrows:
> Package: haxml
> Version: 1.13.1-2
> Severity: important
> 
>   Severity "important" because this is a fairly basic functionality
> gap for an XML writing library.
> 
>   It appears that when you output text in an XML document using
> "literal", the text you pass is just copied to the output verbatim.
> This leads to rather nasty surprises when using HaXml to generate
> new XML content (rather than just blindly shuffling around pieces
> of an input document).
>
>   For instance, see the attached program.  HaXML doesn't escape either
> the double-quote in an attribute value or the brackets in text data,
> leading to an invalid HTML document.
I agree this behaviour can be quite annoying.

>   It might be that "literal" is intended to do this -- but an
> abstraction for XML I/O really should provide a simple mechanism for
> generating valid XML by default, and I can't find a way to get the
> desired result without escaping everything by hand.
I don't know whether this behaviour is intended, but you can work around
it quite easily. Basically you map the xmlEscape function over the
generated Content list. See attached code below.

Malcolm, do the combinators functions, such as literal and replaceAttrs
in the attached file, intentionally refrain from escaping special
caracters?

Second question, could you export escapeContent function in the Escape
module? It can be useful in cases like this.

Greetings Arjan

module Main where

import Text.PrettyPrint
import Text.XML.HaXml.Combinators
import Text.XML.HaXml.Html.Generate
import Text.XML.HaXml.Pretty
import Text.XML.HaXml.Types
import Text.XML.HaXml.Escape

doc :: CFilter
doc = html [
            htitle [
                    literal "What's wrong with HaXML"
                   ],
            replaceAttrs [("class", "the \"best>"), ("bgcolor", "blue")] `o`
                         hbody [
                                literal "<i>XML is a structured container format, not a random byte sequence."
                               ]
           ]

escaper :: Content -> Content
escaper (CElem e) = CElem (xmlEscape stdXmlEscaper e)
escaper x         = x

main :: IO ()
main = print $ vcat $ map content $ map escaper $ doc undefined

Attachment: signature.asc
Description: Dit berichtdeel is digitaal ondertekend

Reply via email to