vendredi 10 juin 2016

How to parse from XML page document to JSON data in Django app


i have some problem. I'm trying to make some app/site with stocks. I have some HTML - table, and i want to put in it some data from XML document which is on some site and looks like this:

<Stocks>
  <PublicationDate>2016-06-10T18:14:06.1146744Z</PublicationDate>
<Items>
  <Stock>
    <Name>FP</Name>
    <Code>FP</Code>
    <Unit>1</Unit>
    <Price>5.0314</Price>
  </Stock>
  <Stock>
    <Name>FPL</Name>
    <Code>FPL</Code>
    <Unit>100</Unit>
    <Price>3.6633</Price>
  </Stock>
 </Items>
</Stocks>

And i need to put this data in to rows in my table. Of course the data should be refreshed automatically when the time will be changed in publicationDate. I only know that this should be done using some ajax code. Can anyone help me with that code? At this moment i have this all as static single site with HTML and CSS.

My html code looks like this:

<div class="prices">
  <table id="price" class="display"  width="100%">
    <thead>
      <tr>
        <th colspan="3" style="background-color:white;">Stock Prices</th>
      </tr>
      <tr>
        <th>Company</th>
        <th>Value</th>
        <th>Actions</th>
      </tr>
     </thead>
     <tbody>
        <tr>
          <td>FP</td>
          <td></td>
          <td>Buy</td>
        </tr>
        <tr>
          <td>FPL</td>
          <td></td>
          <td>Buy</td>
        </tr>
      </tbody>
  </table>
</div>

Anyone knows what code should be attached? This would be very helpful for me. Thanks for help.


Aucun commentaire:

Enregistrer un commentaire