[Tutor] How to get a string from a DOM Text node ?

Zameer Manji zmanji at gmail.com
Sun May 25 22:52:38 CEST 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

I'm trying to extract some information from the following xml file:
http://pastebin.ca/1029125

This is the code that I have so far:

import xml.dom.minidom
file = "Music.xml"
doc = xml.dom.minidom.parse(file)
	
plist = doc.childNodes[1]
	
dict = plist.childNodes[1] #dict contains App version and stuff, as well
as tracks and playlist.
	
tdict = dict.childNodes[21] #dict which contains dicts for each track,
those dicts contain the info
	
print tdict.childNodes[1]
print tdict.childNodes[1].toxml()
print tdict.childNodes[2]

This code prints out the following:

<DOM Element: key at 0xbafb98>
<key>42</key>
<DOM Text node "
                ">

The problem is that the Text node that is printed out is blank, when it
should be 42. What do I need to do so I can get tdict.childNodes[2] to
become a string being "42" ?
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (MingW32)

iQEcBAEBCgAGBQJIOdGWAAoJEA759sZQuQ1B6l8H/2i5FTlsSHPMzlc5ch2/DLiY
0yS1VWNQNuVh40WfK0SVFgsmFxNJ0IFQ+kkJsQPH/mcxQHbP+8iuzKiMuZIpIgUY
Gx/DwfIUzg60W0cCe9gfguvnR/rOXFk/5PuoktWHe9/8bb1BoV+RAFyc9mEWzRzJ
K6+/Rb7ISvQ/ptZ13PNgmX3UkLZU+qIFqlZZ+9rDld4iuyc+toqhdf4nUm7Bemen
XivPf4H/n8OpckYeYKXuKyotacsIZQQraAJevSeiV/EWWrkgHyslktnRwIGVJlmJ
CC8fgKE7DUVrI1PFBa2W48xlTOcpLtg9beB86J5cjNlsbVkSMC+gMiVVAGPooZc=
=yPBg
-----END PGP SIGNATURE-----
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0x50B90D41.asc
Type: application/pgp-keys
Size: 1724 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/tutor/attachments/20080525/571a6e42/attachment-0001.key>


More information about the Tutor mailing list