actually I am working on a small project and need to parse public available XML data. My goal is to write the data to an mysql database for further processing.
XML structure (example):
<parkingAreaStatus>
      <parkingAreaOccupancy>0.2533602</parkingAreaOccupancy>
      <parkingAreaOccupancyTrend>stable</parkingAreaOccupancyTrend>
      <parkingAreaReference targetClass="ParkingArea" id="2[Zeil]" 
       version="1.0"/>
      <parkingAreaStatusTime>2018-02-
       04T01:30:00.000+01:00</parkingAreaStatusTime  
      </parkingAreaStatus>
<parkingAreaStatus>
      <parkingAreaOccupancy>0.34625</parkingAreaOccupancy>
      <parkingAreaOccupancyTrend>stable</parkingAreaOccupancyTrend>
      <parkingAreaReference targetClass="ParkingArea" id="5[Dom / Römer]" 
       version="1.0"/>
      </parkingAreaStatus>
Using the code
import csv
import pymysql
import urllib.request
url = "http://offenedaten.frankfurt.de/dataset/912fe0ab-8976-4837-b591-57dbf163d6e5/resource/48378186-5732-41f3-9823-9d1938f2695e/download/parkdatendyn.xml"
from lxml.objectify import parse
from lxml import etree
from urllib.request import urlopen
locations_root = parse(urlopen(url)).getroot()
locations = list(locations_root.payloadPublication.genericPublicationExtension.parkingFacilityTableStatusPublication.parkingAreaStatus.parkingAreaReference)
print(*locations)
I expected to get a list of all "parkingAreaReference" entries within the XML document. Unfortunately the list is empty.
Playing arround with some code I got the sentiment that only the first block is parsed, I was able to fill the list with the value of "parkingAreaOccupancy" of the "parkingAreaReference" id="2[Zeil]" block by using the code
locations = list(locations_root.payloadPublication.genericPublicationExtension.parkingFacilityTableStatusPublication.parkingAreaStatus.parkingAreaOccupancy)
 print(*locations)
-> 0.2533602
which is not the expected outcome
-> 0.2533602 -> 0.34625
MY question is:
What is the best way to get a matrix i can further work with of all blocks incl. the corresponding values stated in the XML document?
Example output:
A = [[ID:2[Zeil],0.2533602,stable,2018-02-
   04T01:30:00.000+01:00],[id="5[Dom / Römer],0.34625,stable,2018-02-
   04T01:30:00.000+01:00]]
or in general
A = [parkingAreaOccupancy,parkingAreaOccupancyTrend,parkingAreaStatusTime,....],[parkingAreaOccupancy,parkingAreaOccupancyTrend,parkingAreaStatusTime,.....]
After hours of research I hope for some tips from your site
Thank you in advance,
TR
