[Ur] Generating XML

gdp3 at cs.waikato.ac.nz gdp3 at cs.waikato.ac.nz
Tue Sep 15 11:36:56 EDT 2009


Hello,

Just to add to the generally high level of activity on this list, I have a
question.

I'm trying to introduce very simple programmatic generation of XML based
on user input - in the simplest case, I wish to encode lines separated by
newlines with "<p>" tags.

While parsing the string into a list using String.split is
straightforward, the actual means of generating XML is eluding me.  For
example:

fun nl2list s =
  case String.split s #"\n" of
    None => s :: Nil
  | Some (h,t) => h :: nl2list t)

My initial (non-compiling) attempts were something along the lines of:

fun list2p s =
  case s of Nil => <xml/>
          | (h::t) => <xml><p>{[h]}</p>{[list2p t]}</xml>

(note: that is probably not well-formed, I just wrote that out for
illustrative purposes).

In any case, I assume this is a reasonably common task, and I'd be
interested in any input on the "cleanest" way to achieve it?

Thanks,
Gian




More information about the Ur mailing list