[Haskell] Re: understanding HaXml and escaping
S. Alexander Jacobson
alex at alexjacobson.com
Thu Oct 28 12:19:01 EDT 2004
On Thu, 28 Oct 2004, Malcolm Wallace wrote:
> It is a large package with many diverse facilities, so I'm not
> surprised. I take it you have read the ICFP'99 paper linked to from
> the HaXml webpage? To give a fuller answer, it would be helpful to
> know more about your specific XML needs.
It would be helpful to have an example of
using combinators to take a value of type e.g.
import Network.URI
import System.Time
data Foo = Foo {uri::URI,
name::String,
stamp::ClockTime}
and produce e.g. a string such as
<? xml version="1.0" ?>
<? xml-stylesheet type="text/xsl" href="myStyle.xsl"?>
<Foo xmlns:Foo="http://mynamespace"
uri="http://someURL" name="blah"
stamp="Mon, 11 Oct 2004 09:05:31 -0400"/>
Note, I think I've figured out how to do this
using raw types (after modifying to allow PIs in
the prolog!), but I assume using the combinators
is more correct.
> Ah. Escaping of special characters within text is a separate
> issue. It need only be done once, just before output.
> See Text.XML.HaXml.Escape - specifically you want something like
>
> simp2 = document $ Document (Prolog Nothing [] Nothing []) [] $
> xmlEscape stdXmlEscaper $
> Elem "root" [("attr",AttValue [Left "v\"al"])]
> [CString False "<<<<<>>&&&"]
Yes, thank you. I figured this much out after
posting the last mail. It would have been nice if
the documents made the use of both document and
xmlEscape more clear at the beginning. But, I
actually think the document function should
*automatically* implement xmlEscape. Otherwise,
it is too easy for the user to produce incorrect
documents notwithstanding what the library claims
to promise!
> > I assume/hope that the combinators properly
> > encode/escape attribute values and CDATA,
>
> No, at the moment they don't. You can always do it one-shot at the
> end, as in the example above, although it would probably be better
> from a correctness point of view if the combinators did as you suggest.
Actually I think the one shot at the end is
correct. Everything else is manipulation of the
data model and therefore shouldn't worry about
escaping. But, as I said above, the user should
not, by default, have to worry about escaping.
> > And once I've done so, is there a way to put PIs
> > in via the combinators
>
> Currently, there are no combinators specifically for generating PIs
> (simply because no-one has asked for them before), but it would be
> extremely easy to add. For instance:
>
> mkPI :: String -> String -> CFilter
> mkPI pitarget str = \t-> [ CMisc (PI (pitarget,str)) ]
Will this work to insert a PI before the first
element?
-Alex-
______________________________________________________________
S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com
More information about the Haskell
mailing list