[Haskell] HaXml
Dominic Steinitz
dominic.steinitz at blueyonder.co.uk
Sat Nov 27 10:33:33 EST 2004
I'd be grateful for some help on using HaXml.
1. I can parse a String into a Document but it's not clear how you operate on
it as the combinators all operate on Content. The only function I could find
that operated on a Document was "document" in Pretty.
2. I can construct a CFilter but it's not clear how you operate on it. How do
I calculate the number of components of an Element? What I would like to do
is accept "vname" (with 3 elements) and reject "iname" (with 4 elements). I'd
also like to check that the characters in givenName, initial and familyName
are in a given range (for example upper case or between ' ' and '~').
Thanks, Dominic.
import Text.XML.HaXml
import Text.XML.HaXml.Pretty
xmlName =
"<Name><givenName>John</givenName>" ++
"<initial>P</initial>" ++
"<familyName>Smith</familyName>" ++
"</Name>"
d = document $ xmlParse "tmp" xmlName
gn = mkElemAttr "givenName" [] [literal "John"]
i = mkElemAttr "initial" [] [literal "P"]
fn = mkElemAttr "familyName" [] [literal "Smith"]
validName = mkElemAttr "Name" [] [gn,i,fn]
invalidName = mkElemAttr "Name" [] [gn,i,i,fn]
vname = processXmlWith validName
iname = processXmlWith invalidName
*Main> d
<Name
><givenName
>John</givenName
><initial
>P</initial
><familyName
>Smith</familyName></Name>
*Main>
*Main> vname
<?xml version='1.0'?>
<Name
><givenName
>John</givenName
><initial
>P</initial
><familyName
>Smith</familyName></Name>
*Main>
More information about the Haskell
mailing list