2

Possible Duplicate:
python: xml.etree.ElementTree, removing “namespaces”

I have a sample xml document

<?xml version="1.0" encoding="UTF-8"?>
<school xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.school.org">
<name>John</name>
<name>Ferus</name>
<name>Greg</name>
</school>

And I have the below python code to find names,

import xml.etree.ElementTree as ElementTree

with open('sample.xml', 'rt') as f:
    tree = ElementTree.parse(f)
root = tree.getroot()
for name in root.findall("{http://www.school.org}name"):
    print name.text

Providing the namespace each time I search for a tag is clumsy. Is there a better way?

Community
  • 1
  • 1
John Eipe
  • 10,922
  • 24
  • 72
  • 114
  • @MartijnPieters i'm looking for a solution using ElementTree and not lxml2 – John Eipe Nov 15 '12 at 11:25
  • 1
    Perhaps, but unfortunately that still makes your question a duplicate of the other question. You can place a bounty on that question asking for a non-LXML option too if needed. – Martijn Pieters Nov 15 '12 at 11:30

0 Answers0