Getting element by undefinied tag name
<p>I'm parsing an xml document in Python using minidom. </p>

<p>I have an element:</p>

<pre><code>&lt;informationRequirement&gt;
  &lt;requiredDecision href="id"/&gt;
&lt;/informationRequirement&gt;
</code></pre>

<p>The only thing I need is value of href in subelement but its tag name can be different (for example <em>requiredKnowledge</em> instead of <em>requiredDecision</em>; it always shall begin with <em>required</em>).
If the tag was always the same I would use something like:</p>

<pre><code>element.getElementsByTagName('requiredDecision')[0].attributes['href'].value
</code></pre>

<p>But that's not the case. What can be substitute of this knowing that tag name varies?</p>

<p>(there will be always <strong>one</strong> subelement)</p>

<p>If you're always guaranteed to have one subelement, just grab that element:</p>

<pre><code>element.childNodes[0].attributes['href'].value
</code></pre>

<p>However, this is brittle.  A (perhaps) better approach could be:</p>

<pre><code>hrefs = []
for child in element.childNodes:
  if child.tagName.startswith('required'):
    hrefs.append(child.attributes['href'].value)
</code></pre>

python xml-parsing minidom