Bonjour j'extrais des données numériques d'un fichier XML.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
 
<AgendaNr>21</AgendaNr>
<Exchange_AgendaNr>0</Exchange_AgendaNr>
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
 
            if 'AgendaNr' in l:
                AgendaNr = 0
                AgendaNr = l[10:-12]
                print(AgendaNr)
Si je fais un print(AgendaNr)
j'obteins 2 valeurs :

  • 21
  • AgendaNr>0</Exchang


je ne veux que la valeur numérique ?

Comment extraire uniquement cette valeur ?

Voici mon code dans sa totalité :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 
import pyodbc
import glob, sys
import os.path
connection = pyodbc.connect("Driver={SQL Server}; Server=a
cursor = connection.cursor()aaa
 
 
SQLCommand = ("INSERT INTO APPOINTMENT"  "(NUM_APP, NUM_AGENDA) "
          "VALUES (?,?)")
 
os.chdir('//es-server/Achilles/DataAchilles\Export/Tables')
 
for filename in glob.iglob('//es-server/Achilles/DataAchilles\Export/Tables/**/Appointment_*.xml', recursive=True):
    fName = os.path.abspath(os.path.join('data', filename))
 
    file = open(fName, 'r', encoding ='UTF-8')
 
    for l in file:
 
            if 'AppointmentNr' in l:
                AppointmentNr = l[15:-17]
 
            if 'AgendaNr' in l:
                AgendaNr = 0
                AgendaNr = l[10:-12]
                print(AgendaNr)
 
            if 'PatientAddressNr' in l:
                PatientAddressNr = 0
                PatientAddressNr = l[18:-20]
 
                try:
 
                    Values = [AppointmentNr, AgendaNr]
 
                    cursor.execute(SQLCommand,Values)
                    connection.commit()
                except:
                        print ("Unexpected error:", sys.exc_info()[0])