Dear Aleksandra, dear Folks,
On Thu, Oct 30, 2014 at 11:51:11AM +0000, Aleksandra Pawlik wrote:
> Hello!
>
> We are running an SWC course at Manchester as a part of a one week
> training for MSc students in Clinical Bioinformatics. We have 2.5 days
> for SWC and then the students will work on a small programming task in
> teams. The idea is that they will need to grab some XML files, parse
> them and then do some rather simple manipulation with the outputs.
>
> At the end of the SWC (we'll be using Python) we want to show them how
> to use a _simple_ library for XML. So before I dive into Google, I
> though I'd be lazy and ask the SWC community:
> 1) Has anyone created an SWC module on XML? If yes, can you point me to it?
> 2) Which Python library from XML would you recommend?
The standard xml.dom and xml.dom.minidom modules have so far been good
enough for my own basic XML hacking requirements. Here's a minimal
example for parsing some XML, adding an element and then writing it:
import sys
import xml.dom.minidom
x = u"""<?xml version="1.0" encoding="UTF-8"?>
<demo>
<title>some title</title>
<list>
<item>item from file</item>
</list>
</demo>
"""
d = xml.dom.minidom.parseString(x)
l = d.getElementsByTagName('list')[0]
e = d.createElement('item')
t = d.createTextNode('generated item')
e.appendChild(t)
l.appendChild(e)
d.writexml(sys.stdout)
Whether this is good enough for your course largely depends on what the
"rather simple manipulations" you aim for. If they're this simple I'd
run with these standard modules, they at least do have the advantage
that students won't have to faff around with installing additional
libraries if they want to revisit / build on what they've done in
the course.
Best regards & good luck / happy carpentering, Jan
_______________________________________________
Discuss mailing list
[email protected]
http://lists.software-carpentry.org/mailman/listinfo/discuss_lists.software-carpentry.org