Vorerst mal der Code:
Code: Alles auswählen
from xml.sax import make_parser, handler
import sqlite3
import time
class OmdsHeader(handler.ContentHandler):
def __init__(self) -> None:
self.header_list = []
self.vu_list = []
def startElement(self, name, attrs):
if name == 'PAKET':
self.header_list.append(attrs['MaklerID'])
self.header_list.append(attrs['PaketZpktErstell'])
self.header_list.append(attrs['PaketZpktLetztErstell'])
self.header_list.append(attrs['PaketInhCd'])
self.header_list.append(attrs['PaketUmfCd'])
self.header_list.append(attrs['OMDSVersion'])
self.header_list.append(attrs['VUVersion'])
self.header_list.append(attrs['DVRNrAbs'])
self.header_list.append(attrs['PaketKommentar'])
self.vu_list.append(self.header_list)
def characters(self, content):
pass
def endElement(self, name):
pass
def getVuNr(self):
return self.vu_list
parser = make_parser()
b = OmdsHeader()
parser.setContentHandler(b)
parser.parse("muki.xml")
print(b.getVuNr())
Code: Alles auswählen
<?xml version="1.0" encoding="utf-8"?>
<OMDS xmlns="urn:omds20" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:omds20 .\omds211-00.xsd">
<PAKET VUNr="063" MaklerID="7016281" PaketZpktErstell="2021-08-23T04:56:11.515" PaketZpktLetztErstell="2021-08-23T04:56:11.515" PaketInhCd="VV" PaketUmfCd="G" OMDSVersion="211-00" VUVersion="211-00" DVRNrAbs="2110857" PaketKommentar="muki Bestandsdaten erstellt am 23.08.2021">
</PAKET>
<PAKET VUNr="063" MaklerID="7016282" PaketZpktErstell="2021-08-23T04:56:11.515" PaketZpktLetztErstell="2021-08-23T04:56:11.515" PaketInhCd="VV" PaketUmfCd="G" OMDSVersion="211-00" VUVersion="211-00" DVRNrAbs="2110857" PaketKommentar="muki Bestandsdaten erstellt am 23.08.2021">
</PAKET>
</OMDS>
[['7016281', '2021-08-23T04:56:11.515', '2021-08-23T04:56:11.515', 'VV', 'G', '211-00', '211-00', '2110857', 'muki Bestandsdaten erstellt am 23.08.2021', '7016282', '2021-08-23T04:56:11.515', '2021-08-23T04:56:11.515', 'VV', 'G', '211-00', '211-00', '2110857', 'muki Bestandsdaten erstellt am 23.08.2021'],
['7016281', '2021-08-23T04:56:11.515', '2021-08-23T04:56:11.515', 'VV', 'G', '211-00', '211-00', '2110857', 'muki Bestandsdaten erstellt am 23.08.2021', '7016282', '2021-08-23T04:56:11.515', '2021-08-23T04:56:11.515', 'VV', 'G', '211-00', '211-00', '2110857', 'muki Bestandsdaten erstellt am 23.08.2021']]
Sollte aber so ausschauen:
[['7016281', '2021-08-23T04:56:11.515', '2021-08-23T04:56:11.515', 'VV', 'G', '211-00', '211-00', '2110857', 'muki Bestandsdaten erstellt am 23.08.2021'],
['7016282', '2021-08-23T04:56:11.515', '2021-08-23T04:56:11.515', 'VV', 'G', '211-00', '211-00', '2110857', 'muki Bestandsdaten erstellt am 23.08.2021']]