title: How can I check the existence of attributes and tags in XML before parsing?
body: <p>I'm parsing an XML file via Element Tree in python and and writing the content to a cpp file. </p>
  
  <p>The content of children tags will be variant for different tags.  For example first event tag has party tag as child but second event tag doesn't have. </p>
  
  <p>-->How can I check whether a tag exists or not before parsing?</p>
  
  <p>-->Children has value attribute in 1st event tag but not in second. How can I check whether an attribute exists or not before taking it's value.</p>
  
  <p>--> Currently my code throws an error for non existing party tag and sets a "None" attribute value for the second children tag.</p>
  
  <pre><code>&lt;main&gt;
    &lt;event&gt;
      &lt;party&gt;Big&lt;/party&gt;
      &lt;children type="me" value="3"/&gt;
    &lt;/event&gt;
  
    &lt;event&gt;
      &lt;children type="me"/&gt;
    &lt;/event&gt;
  
  &lt;/main&gt;
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>import xml.etree.ElementTree as ET
  tree = ET.parse('party.xml')
  root = tree.getroot()
  for event in root.findall('event'):
      parties = event.find('party').text
      children = event.get('value')
  </code></pre>
  
  <p>I want to check the tags and then take their values.</p>