snoyberg/xml

Example on parsing two or more element tag with xml-conduit.

Closed this issue · 1 comments

<dataset xmlns="http://www.example.com">
	<sitedata>
		<name>Posts</name>
		<db>mysite</db>
		<infos>
			<info key="-2" case="case-sensitive">template</info>
			<info key="12" case="case-sensitive">talks</info>
			<info key="3" case="case-sensitive">posts</info>
		</infos>
	</sitedata>
	<user>
		<id>123</id>
		<title>Post 1</title>
		<author>
			<id>1</id>
			<first_name>Ginelle</first_name>
			<last_name>Resun</last_name>
			<email>gresun0@imageshack.us</email>
			<gender>Female</gender>
			<ip_address>96.243.44.50</ip_address>
		</author>
	</user>
	<user>
		<id>43</id>
		<title>Post 63</title>
		<author>
			<id>38</id>
			<first_name>Ysabel</first_name>
		    <last_name>Ganders</last_name>
		    <email>yganders1@nsw.gov.au</email>
		    <gender>Female</gender>
		    <ip_address>253.119.196.198</ip_address>
		</author>
	</user>
</dataset>
data SiteData = SiteData { name :: Text, db :: Text, infos :: [Info] }
data Info = Info { key :: Integer, textcase :: Text, value :: Text }
data User = User { id :: Integer, title :: Text, author :: Author}
data Author = Author {aid :: Integer, firstName :: Text, lastName :: Text, email :: Text, gender :: Text, ip :: Text }

I want to parse all the elements such that lets say I have a data types as SiteData and User which consists of all the values in the tags. And the result I would want is (SiteData, [User] ). How would I go about this ?

k0ral commented

The Text.XML.Stream.Parse module provides an example of parser for simple algebraic data-types such as yours.