Trying to iterate through XML : can't get subnode's values
<p>I need to process a huge file with many nodes structured likes this</p>

<pre><code>&lt;category name="28931778o.rjpf"&gt;
&lt;name&gt;RequestedName&lt;/name&gt;
&lt;root&gt;0&lt;/root&gt;
&lt;online&gt;1&lt;/online&gt;
&lt;description xml:lang="pt-PT"&gt;mydescription &lt;/description&gt;
&lt;category-links/&gt;
&lt;template/&gt;
&lt;parent name="PTW-0092"/&gt;
&lt;custom-attributes&gt;
&lt;custom-attribute name="sortkey" dt:dt="string"&gt;RequestedValue&lt;/custom-attribute&gt;
&lt;custom-attribute name="ShortLink" dt:dt="string" xml:lang="pt-PT"&gt;/Requested_Url.html&lt;/custom-attribute&gt;
&lt;custom-attribute name="ShortLinkActivate" dt:dt="string" xml:lang="pt-PT"&gt;true&lt;/custom-attribute&gt;
...
&lt;/category&gt;
</code></pre>

<p>I need to get back for each category the 3 requested Values.
I use Python .27 and etree.
when running</p>

<pre><code>for elem in tree.iterfind('{http://www.cc.com/a}category'):
    requestedName = elem.find('{http://www.cc.com/a}name').text
    print requestedName
</code></pre>

<p>It works fine</p>

<p>when running </p>

<pre><code>for elem in tree.iterfind('{http://www.cc.com/a}category/{http://www.cc.com/a}custom-attributes/{http://www.cc.com/a}custom-attribute[@name="sortkey"]'):
    print elem.text
</code></pre>

<p>it works fine also
Problem comes when I want to retreive all three values. I try to find a "category" node and inside it to find the 2 requested values</p>

<pre><code>for elem in tree.iterfind('{http://www.cc.com/a}category'):
    requestedName = elem.find('{http://www.cc.com/a}name').text
    print requestedName
    Requestedsortkey = elem.find('./{http://www.cc.com/a}custom-attributes/{http://www.cc.com/a}custom-attribute[@name="sortkey"]')
    print Requestedsortkey.text
    RequestedUrl = elem.find('./{http://www.cc.com/a}custom-attributes/{http://www.cc.com/a}custom-attribute[@name="ShortLink"]')
    print RequestedUrl.text
</code></pre>

<p>Program crashes with his error message 
AttributeError: 'NoneType' object has no attribute 'text'</p>

<p>Who can help?</p>

<p>You are right Dopstar ! Many thanks</p>

<pre><code>for elem in tree.iterfind('{http://www.cc.com/a}category'):
    requestedName = elem.find('{http://www.cc.com/a}name').text
   print requestedName
   Requestedsortkey = elem.find('{http://www.cc.com/a}custom-attributes/{http://www.cc.com/a}custom-attribute[@name="sortkey"]')
    if Requestedsortkey &lt;&gt; None:
       print Requestedsortkey.text
    RequestedUrl = elem.find('{http://www.cc.com/a}custom-attributes/{http://www.cc.com/a}custom-attribute[@name="ShortLink"]')
    if RequestedUrl &lt;&gt; None : 
       print RequestedUrl.text
</code></pre>

python xml-parsing lxml elementtree