How to get the updates from XML file in Python?
<p>I am a newbie to Python. I have an XML file in the server which will be updated by a device with notifications periodically like below.</p>

<pre><code>&lt;notifications
    xmlns="http://XXXXX"&gt;
    &lt;notification&gt;
        &lt;received&gt;2016-09-04T13:48:57Z&lt;/received&gt;
        &lt;source-address&gt;x.x.x.x&lt;/source-address&gt;
        &lt;notification-type&gt;type-1&lt;/notification-type&gt;
        &lt;message&gt;message-1&lt;/message&gt;
    &lt;/notification&gt;
    &lt;notification&gt;
        &lt;received&gt;2016-09-04T13:49:21Z&lt;/received&gt;
        &lt;source-address&gt;X.X.X.X&lt;/source-address&gt;
        &lt;notification-type&gt;type-2&lt;/notification-type&gt;
        &lt;message&gt;message-2&lt;/message&gt;
    &lt;/notification&gt;
    &lt;notification&gt;
        &lt;received&gt;2016-09-04T13:52:38Z&lt;/received&gt;
        &lt;source-address&gt;X.X.X.X&lt;/source-address&gt;
        &lt;notification-type&gt;type-3&lt;/notification-type&gt;
        &lt;message&gt;message-3&lt;/message&gt;
    &lt;/notification&gt;
    &lt;notification&gt;
        &lt;received&gt;2016-09-04T14:01:21Z&lt;/received&gt;
        &lt;source-address&gt;X.X.X.X&lt;/source-address&gt;
        &lt;notification-type&gt;type-4&lt;/notification-type&gt;
        &lt;message&gt;message-4&lt;/message&gt;
    &lt;/notification&gt;
    &lt;notification&gt;
        &lt;received&gt;2016-09-04T14:01:51Z&lt;/received&gt;
        &lt;source-address&gt;X.X.X.X&lt;/source-address&gt;
        &lt;notification-type&gt;type-5&lt;/notification-type&gt;
        &lt;message&gt;message-5&lt;/message&gt;
    &lt;/notification&gt;
&lt;/notifications&gt;
</code></pre>

<p>I am interested in getting the values of <code>&lt;notification-type&gt; and &lt;message&gt;</code> whenever device post notification on to this file. Is there a way I can do this in Python?</p>

<p>two separate issues â first issue is monitoring a file for changes â¦ this looks like itâs been addressed </p>

<ul>
<li><a href="http://stackoverflow.com/questions/182197/how-do-i-watch-a-file-for-changes-using-python">How do I watch a file for changes using Python?</a> </li>
<li><a href="http://stackoverflow.com/questions/597903/monitoring-files-directories-with-python">Monitoring files/directories with python</a></li>
</ul>

<p>second is reading the XML file in Python </p>

<pre><code>import xml.etree.ElementTree as Et

def process(notification):

    received          = notification[0].text
    print (received)

    notification_type = notification[2].text
    print (notification_type)


xml = Et.ElementTree()
xml.parse('notifications.xml')
root = xml.getroot()

for notification in root:
    process(notification)
</code></pre>

python xml notifications