<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">

<head>
<meta http-equiv=Content-Type content="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
 /* Font Definitions */
 @font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page Section1
        {size:612.0pt 792.0pt;
        margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.Section1
        {page:Section1;}
-->
</style>
<!--[if gte mso 9]><xml>
 <o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
 <o:shapelayout v:ext="edit">
  <o:idmap v:ext="edit" data="1" />
 </o:shapelayout></xml><![endif]-->
</head>

<body lang=EN-GB link=blue vlink=purple>

<div class=Section1>

<p class=MsoNormal>Hello Chaps,<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>I&#8217;m looking for some help with XML parsing, I&#8217;ve
been playing around with this over the past few days and the only solution I
can come up with seems to be a little slow and also leaves what I think is a memory
leak in my application, which causes all kinds of problems. <o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>I have a very simple XML file which I need to loop over the
elements and extract the attribute information from, but the loop must be
conditional as the attributes must meet a certain criteria.<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>My current solution is using minidom, which I&#8217;ve read
isn&#8217;t one of the better parsers, if anyone knows of any that are better
for the task I would love to hear it, the content is extracted regularly so
whatever we chose needs to be quick, and validation isn&#8217;t so important.
Take a look at this brief example of the XML we&#8217;re dealing with:<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>&lt;schedules name=&quot;Default event&quot;
location=&quot;this is the location of the event&quot;&gt;<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;event name=&quot;This is an event&quot; location=&quot;At my house&quot;
type=&quot;1&quot; <span style='font-size:9.0pt;font-family:"Courier New"'>start=&quot;2007-01-01
00:00:00&quot; end=&quot;2007-01-01 00:00:00&quot;</span> /&gt;<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;event name=&quot;And Another&quot; location=&quot;At work&quot;
type=&quot;2&quot; <span style='font-size:9.0pt;font-family:"Courier New"'>start=&quot;2007-01-01
00:00:00&quot; end=&quot;2007-01-01 00:00:00&quot;</span> /&gt;<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;event name=&quot;This is some more&quot; location=&quot;At the cafe&quot;
type=&quot;1&quot; <span style='font-size:9.0pt;font-family:"Courier New"'>start=&quot;2007-01-01
00:00:00&quot; end=&quot;2007-01-01 00:00:00&quot;</span> /&gt;<o:p></o:p></p>

<p class=MsoNormal>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;event name=&quot;And one last one&quot; location=&quot;At my house&quot;
type=&quot;3&quot; <span style='font-size:9.0pt;font-family:"Courier New"'>start=&quot;2007-01-01
00:00:00&quot; end=&quot;2007-01-01 00:00:00&quot;</span> /&gt;<o:p></o:p></p>

<p class=MsoNormal>&lt;/schedules&gt;<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>Now this file details events which are possibly going to
occur over the next couple of weeks. Now what I need to do is have a function
which is called &#8216;getCurrentEvent()&#8217; which will return any events
that should be occurring at this point in time, or now(). The &#8216;Type&#8217;
attribute details how often the event it likely to reoccur, 1 being daily, 2
being weekly and so on, if no elements are found which are occurring in this
time and date then I would like it to return the default event which is defined
in the attributes of the &#8216;schedules&#8217; tag.<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>The current solution I have put together uses minidom to
loop over the elements from the XML and then does a conditional against a
python module called &#8216;period.py&#8217;. This works ok, but it&#8217;s
very slow and also contains a memory leak. I need something better and I have
no real idea or experience of how to achieve it which is why I&#8217;m here
with you good gentlemen to try and find a solution.<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>I appreciate this could be quite a challenging task so would
be happy to pay someone for their time to solve this for me, you may want to
contact me off list to talk about that though and we&#8217;d be hoping to get
this sorted ASAP.<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>Thanks guys,<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

<p class=MsoNormal>Rob<o:p></o:p></p>

<p class=MsoNormal><o:p>&nbsp;</o:p></p>

</div>

</body>

</html>