How do you use Python elementTree to grab ASCII text from XML children?



I am running the following code, however the unicode result is hiding the true XML. Is there a way I can force walk through the children in the xml and return the proper XML, not the unicode?


Thanks



import xml.etree.ElementTree as ET
file="/home/pi/bin/test/test_xml3.xml"
parser = ET.XMLParser(encoding="ascii")

root = ET.parse(file)

for elements in root.iter('kiddy'): #iterate through each element
print elements.text


the example file which is causing the issues is this, specifically unicode result strips out the quot; and amp;



<root>
<kiddy> shghsgdh ; sdjhgsjhsjdh ; sjhsjhdsjdh </kiddy>
<kiddy name="All Shows" thumb="special://home/addons/plugin.video.plexbmc/resources/plex.png">ActivateWindow(10025,&quot;plugin://plugin.video.plexbmc/?mode=0&amp;url=http%3a%2f%2f192.168.0.1%3a32400%2flibrary%2fsections%2f2%2fall&quot;,return)</kiddy>
</root>

No comments:

Post a Comment