[Haskell] HaXml and XML Schema

Frank Atanassow franka at cs.uu.nl
Wed Mar 17 14:24:08 EST 2004

On Mar 10, 2004, at 8:56 AM, s_mazanek at gmx.de wrote:
> Example (readers familiar with the problem may
> skip this):
> <salutation>Dear Mr.<name>Robert Smith</name>.</salutation>
> This structure is represented by the XML Schema
> <xsd:element name="salutation">
> <xsd:complexType mixed="true">
> <xsd:sequence>
> <xsd:element name="name" type="xsd:string"/>
> </xsd:sequence>
> </xsd:complexType>
> </xsd:element>
> How would you represent this in Haskell?
> A first idea may be to store the enclosing strings:
> data Salutation = Salutation String Name String
> This approach is not scaling well. E.g., there may be multiple
> names in the text...

No, according to the content model, there must be exactly one 
occurrence of "name" in the content of "salutation": not zero, and not 
more than one. To allow zero or more you need to add minOccurs and/or 
maxOccurs attributes. This is one of the ways that mixed content in XML 
Schema differs from that in DTD's, and is treated in the references 
Johan posted.

So, on the contrary, your first declaration:

   data Salutation = Salutation String Name String

is a better translation of this schema (fragment), than your second 

   data Salutation' = Salutation' [Either Char Name]


More information about the Haskell mailing list