SAX/Python : read an xml from the end to the top

kepioo nkammah at yahoo.fr
Wed Mar 8 01:48:19 CET 2006


An example ( i changed the content to make it easier) :

###################  input file ####################3

<root>
<case>
  <TimeStamp Date="Mon Feb 20 19:40:28 SGT 2006" >
    <Message>fruits</Message>
    <Elements>
      <Element name="apple">5</Element>
      <Element name="banana">10</Element>
      <Element name="peach">25</Element>
   </Elements>
 </TimeStamp>
</case>

<case>
  <TimeStamp Date="Mon Feb 20 19:45:28 SGT 2006" >
    <Message>names</Message>
      <Elements>
        <Element name="CEO">vincent</Element>
        <Element name="Analysit">Robert</Element>
     </Elements>
  </TimeStamp>
</case>

<case>
  <TimeStamp Date="Mon Feb 20 19:50:28 SGT 2006" >
    <Message>open the car</Message>
  </TimeStamp>
</case>


<case>
  <TimeStamp Date="Mon Feb 20 19:55:28 SGT 2006" >
    <Message>fruits</Message>
    <Elements>
      <Element name="peach">25</Element>
      <Element name="apple">8</Element>
      <Element name="cherry">120</Element>
    </Elements>
  </TimeStamp>
</case>
</root>
##############################################3

The script I want to write has to track any change in the input
file(what we want to track are parameters in the script. Here for
instance,  the number of apple and cherry). The ouput file for this
example would be ( we write it as a stream):

################### OutPut file #################################
<track>
<case>
  <TimeStamp Date="Mon Feb 20 19:40:28 SGT 2006" >
    <Message>fruits</Message>
    <Elements>
      <Element name="apple">5</Element>
    </Elements>
  </TimeStamp>
</case>

<case>
  <TimeStamp Date="Mon Feb 20 19:55:28 SGT 2006" >
    <Message>fruits</Message>
    <Elements>
      <Element name="apple">8</Element>
    </Elements>
  </TimeStamp>
</case>

<case>
  <TimeStamp Date="Mon Feb 20 19:55:28 SGT 2006" >
    <Message>fruits</Message>
    <Elements>
      <Element name="cherry">120</Element>
    </Elements>
  </TimeStamp>
</case>
</track>
############################################33333
The input file keeps being generated. The ouput file is generated on
request. Both are streamed based : we happend to the end of the file.

Any suggestion?




More information about the Python-list mailing list