V
V
Vladislav2021-07-14 12:20:26
Python
Vladislav, 2021-07-14 12:20:26

How to parse the required data from a Python XML file?

there is a huge number of xml files that are in such a directory (number_date / number xml) for example
1_01.07.21/1.xml
1_01.07.21/2.xml
.....
2__01.07.21/1.xml
2__01.07.21/2. xml
.....
99__01.07.21/999.xml
it is necessary to form xlsx in which there will be columns (date_number, xml number, and pull out dSessionDate, tSessionTime from the file itself) I

tried to figure it out with this example , but it didn’t work out ...

<?xml version ="1.0" encoding="windows-1251"?>
<PASP_ROOT>
Version = 1.0.0.0
tSessionTime = 6:48:45.000000
dSessionDate = 20/1/2018
dSessionDateUTC = 20/1/2018
tSessionTimeUTC = 3:48:45.000000
cProcLevel = "1"
bSunAngle = 27.6861100891958, 163.464665297173
<Device>
cDeviceName = "MSS1"
nMatrixNumber = 7
cDeviceTxtName = "МСС"
<Ch1>
nChannelNumber = 1
bSpectralZone = 0.47, 0.53
bSPEA = 3.0411926107072, 3.36152889623265, 3.6818651817581, 4.00220146728354, 4.32253775280899, 
bSPEA_APPROX = 0, 124, 239, 255, 3.0411926107072, 42.7628920158625, 116.530816627447, 143.897034622132
bEA = 0.182471556642432, 0.201691733773959, 0.220911910905486, 0.240132088037013, 0.259352265168539, 0.278572442300066, 0.297792619431593, 0.31701279656312, 0.336232973694646, 0.355453150826173, 
</Ch1>
</Device>
<Matrix>
nWidth = 1920
nHeight = 985
nSamples = 1
nBitsPerPixel = 8
</Matrix>
</PASP_ROOT>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2021-07-14
@Tomio

Try using the pandas library to load the xml and save the xlsx . After loading xml, you will receive a DataFrame object (an analogue of an Excel table), which will be very convenient to work with (filter records, search for the ones you need, convert types, rename columns). Googling in this direction in more detail. I think this might help your question.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question