I am trying to parse an XML dump of the Wiktionary but probably I am missing something since I don't get anything as output.
This is a similar but much shorter xml file:
<mediawiki xmlns="http://www.mediawiki.org/xml/export-0.8/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mediawiki.org/xml/export-0.8/ http://www.mediawiki.org/xml/export-0.8.xsd" version="0.8" xml:lang="it">
<page>
<title>bigoto</title>
<ns>0</ns>
<id>24840</id>
<revision>
<id>1171207</id>
<parentid>743817</parentid>
<timestamp>2011-12-18T19:26:42Z</timestamp>
<contributor>
<username>GnuBotmarcoo</username>
<id>14353</id>
</contributor>
<minor />
<comment>[[Wikizionario:Bot|Bot]]: Sostituisco template {{[[Template:in|in]]}}</comment>
<text xml:space="preserve">== wikimarkups ==</text>
<sha1>gji6wqnsy6vi1ro8887t3bikh7nb3fr</sha1>
<model>wikitext</model>
<format>text/x-wiki</format>
</revision>
</page>
</mediawiki>
I am interest in parsing the content of the <title>
element if the <ns>
element equals 0.
This is my script
import xml.etree.ElementTree as ET
tree = ET.parse('test.xml')
root = tree.getroot()
for page in root.findall('page'):
ns = int(page.find('ns').text)
word = page.find('title').text
if ns == 0:
print word