[Tutor] XML: Expletive Deleted

doug shawhan doug.shawhan at gmail.com
Sat Jun 10 00:28:25 CEST 2006

I realize XML is going to save us all from something or other, but I just
can't get my head around it.

I have been trying to do what should be a very simple action: Extract values
from element tags.

I first grab my data from a website with httplib:

>> connection = httplib.HTTPSConnection(serverUrl)
>> connection.request("POST", serverDir, buildRequestXml("ReturnAll", "1"),
>> response = connection.getresponse()

>> from xml.dom.minidom import parse, parseString

>> data = response.read()
>> connection.close()
>> response = parseString(data)
>> itemIDs = response.getElementsByTagName("ItemID")
>> response.unlink()

I have tried everything I can find to extract the values from the <ItemID>

>> for item in itemIDs:
>>     print item


<DOM Element: ItemID at 0x7f532c0c>
<DOM Element: ItemID at 0x7f5400cc>
<DOM Element: ItemID at 0x7f54656c>
<DOM Element: ItemID at 0x7f54ea0c>
<DOM Element: ItemID at 0x7f555eac>

Okay, no problem. Now all I have to do is figure out which
particlular.string.of.words.interconnected.by.periods to pass to extract the

>> for item in itemIDs:
>>     print item.nodeValue

Seems logical:


Oh for crying out loud ...

Hmmm ... I have saved the output from response.read() to a file and sure
enough, amid all the other element tags, I find the expected values in

My problem is: I'm ignorant. I don't know whether my data is being returned
from parseString() as text, or a list or a beautiful rainbow made of
skittles and pixie droppings.  The Python/XML howto and the bajillion other
"XML made clear to YOU!" sites I have looked at have left me more confused
...  I'm just completely lost in the (apparently arbitrary) nomeclature of
lists, nodes, elements, trees, habitrails and intestines. (Yes, I'm just
complaining now, but dang it! I'm frustrated!


Could someone kindly point out where I am going wrong and perhaps send me to
a very *practical* introduction to reading data from a dom?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060609/0b888d30/attachment.htm 

More information about the Tutor mailing list