Access XML element by name
<p><a href="http://i.stack.imgur.com/Yp0yd.png" rel="nofollow"><img src="http://i.stack.imgur.com/Yp0yd.png" alt="enter image description here"></a></p>

<p>Im using <code>xml.etree.ElementTree</code> to parse my XML data. I'm trying to get the text value of <code>&lt;Name&gt;</code></p>

<p>This is my code.</p>

<pre><code>for Content in Zone[0]:
    print(Content.find('Name').text)
</code></pre>

<p>It is returning as NoneObject</p>

<p>However, I am able to access the Element using</p>

<pre><code>for Content in Zone[0]:
    print(Content[12].text)
</code></pre>

<p>I think I might have found the problem as when I print the tags out, it doesn't display <code>Name</code> and instead it displays <code>{http://schemas.datacontract.org/2004/07/}Name</code>. What is the extra data infront of the tag name?</p>

<p>Your XML is likely has default namespace -namespace declared with no prefix-. Notice that descendant elements without prefix inherits default namespace implicitly. You can handle default namespace the way you would <a href="http://stackoverflow.com/questions/14853243/parsing-xml-with-namespace-in-python-via-elementtree">handle prefixed namespaces</a>; just map a prefix to the namespace URI, and use that prefix along with element name to reference element in namespace :</p>

<pre><code>namespaces = {'d': 'http://schemas.datacontract.org/2004/07/'}
for Content in Zone[0]:
    print(Content.find('d:Name', namespaces).text)
</code></pre>

python xml