I realize XML is going to save us all from something or other, but I just can't get my head around it. <br>
<br>
I have been trying to do what should be a very simple action: Extract values from element tags.<br>
<br>
I first grab my data from a website with httplib:<br>
<br>
<br>
>> connection = httplib.HTTPSConnection(serverUrl)<br>
>> connection.request("POST", serverDir, buildRequestXml("ReturnAll", "1"), buildHttpHeaders())<br>
>> response = connection.getresponse()<br>
<br>
>> from xml.dom.minidom import parse, parseString<br>
<br>
>> data = response.read()<br>
>> connection.close()<br>
>> response = parseString(data)<br>
>> itemIDs = response.getElementsByTagName("ItemID")<br>
>> response.unlink()<br>
<br>
<br>
I have tried everything I can find to extract the values from the <ItemID> elements:<br>
<br>
>> for item in itemIDs:<br>
>> print item<br>
<br>
yeilds<br>
<br>
<DOM Element: ItemID at 0x7f532c0c><br>
<DOM Element: ItemID at 0x7f5400cc><br>
<DOM Element: ItemID at 0x7f54656c><br>
<DOM Element: ItemID at 0x7f54ea0c><br>
<DOM Element: ItemID at 0x7f555eac><br>
<br>
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 values.<br>
<br>
>> for item in itemIDs:<br>
>> print item.nodeValue<br>
<br>
Seems logical:<br>
<br>
None<br>
None<br>
None<br>
None<br>
None<br>
<br>
Oh for crying out loud ...<br>
<br>
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 <ItemID><br>
<br>
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!<br>
<br>
*ahem*<br>
<br>
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?<br>
<br>
Thanks!<br>
<br>
<br>
<br>
<br>