I recently wrote the following Python function which will take a Google Picasa contacts.xml file and output a dictionary with ID and Name.
def read_contacts_file(fn):
import xml.etree.ElementTree
x = xml.etree.ElementTree.ElementTree(file=fn)
q = [(u.attrib["id"], u.attrib["name"]) for u in x.iter("contact")]
return dict(q)
What this function does is return a dictionary (hashtable, map) with the ID being the key and the Name being the value.
The file itself has the form:
<contacts>
<contact id="f5fdaaee2e80fa01" name="Person A" display="A"/>
<contact id="8d5256298fd43877" name="Person B" display="B"/>
</contacts>
What’s the simplest way I can implement this in Haskell?
Just wanted to let you know that with everyone’s help, I’ve managed to come up with the following which makes sense to me. Thanks.
parseContactsData = M.fromList . runLA (xread >>> f)
where f =
getChildren
>>> hasName "contact"
>>> getAttrValue "id" &&& getAttrValue "name"
Here’s an example doing it with HXT