Bonjour,
Depuis pas mal de temps je bloque sur un lecteur XML qui doit récupérer seulement quelque infos d'un fichier xml, le but sera de les affiché dans un QLineEdit.
Donc j'ai coder un lecteur avec QXmlStreamReader, mais celui-ci marche sauf que comme par hasard les valeur qui m'intéresse sont en double (voir document plus bas).
Donc si la valeur est en double il efuse de la récupérer. Si elle est pas en double là aucun soucis il la récupère.
Voici le code que j'ai fais:
Mon problème est de savoir comment dire a mon Lecteur XML pour chaque fonction, arrête de lire le document quand tu as la valeur ?
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78 bool Informations::read(QIODevice *device) { xml.setDevice(device); if (xml.readNextStartElement()) { if (xml.name() == "plist" && xml.attributes().value("version") == "1.0"){ readName(); readIdentifier(); readVersion(); } else xml.raiseError(QObject::tr("Le fichier n'est pas un fichier plist version 1.0")); } return !xml.error(); } void Informations::readName() { qDebug() << "Entrée dans Informations::readName"; while (xml.readNextStartElement()) { if (xml.name() == "key") { QString cle = xml.readElementText(); if (cle == "CFBundleName") { xml.readNextStartElement(); if (xml.name() == "string") { QString str = xml.readElementText(); m_kextName = str; } } else if (cle == "CFBundleExecutable"){ xml.readNextStartElement(); if (xml.name() == "string") { QString str = xml.readElementText(); m_kextName = str; } } } } qDebug() << "le nom est: " << m_kextName; } void Informations::readIdentifier() { qDebug() << "Entrée dans Informations::readIdentifier"; while (xml.readNextStartElement()) { if (xml.name() == "key") { QString cle = xml.readElementText(); if (cle == "CFBundleIdentifier") { xml.readNextStartElement(); if (xml.name() == "string") { QString str = xml.readElementText(); m_kextIdentifier = str; break; } } } } qDebug() << "le nom est: " << m_kextIdentifier; } void Informations::readVersion() { //qDebug() << "Entrée dans Informations::readVersion"; while (xml.readNextStartElement()) { if (xml.name() == "key") { QString cle = xml.readElementText(); if (cle == "CFBundleVersion") { xml.readNextStartElement(); if (xml.name() == "string") { QString str = xml.readElementText(); m_kextVersion = str; } } } } //qDebug() << "le nom est: " << m_kextVersion; }
Voici à quoi ressemble les fichier XML sur lesquel mon code travail :
PS : Je précise que j'ai lu la doc Qt sur QXmlStreamReader et aussi les tutoriels QT /FAQ QT et FAQ Xml sur le site.
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>CFBundleDevelopmentRegion</key> <string>English</string> <key>CFBundleInfoDictionaryVersion</key> <string>6.0</string> <key>CFBundleVersion</key> <string>5.5.0</string> <key>CFBundleShortVersionString</key> <string>5.5.0</string> <key>CFBundleName</key> <string>UAD-1 Powered Plug-Ins</string> <key>CFBundleGetInfoString</key> <string>5.5.0 10-26-2009 16:20 © Universal Audio, Inc. 2001-09</string> <key>CFBundlePackageType</key> <string>KEXT</string> <key>CFBundleSignature</key> <string>UAD1</string> <key>CFBundleExecutable</key> <string>UADDriver</string> <key>CFBundleIdentifier</key> <string>com.uaudio.driver.HypKern</string> <key>IOKitPersonalities</key> <dict> <key>UAD-1</key> <dict> <key>CFBundleIdentifier</key> <string>com.uaudio.driver.HypKern</string> <key>IOClass</key> <string>com_uaudio_driver_HypKern</string> <key>IONameMatch</key> <array> <string>pci110b,4</string> </array> <key>IOProviderClass</key> <string>IOPCIDevice</string> </dict> </dict> <key>OSBundleLibraries</key> <dict> <key>com.apple.kernel.mach</key> <string>6.0</string> <key>com.apple.kernel.bsd</key> <string>6.0</string> <key>com.apple.kernel.libkern</key> <string>6.0</string> <key>com.apple.kernel.iokit</key> <string>6.0</string> <key>com.apple.iokit.IOPCIFamily</key> <string>1.4</string> <key>com.uaudio.kext.HypAudio</key> <string>5.5.0</string> </dict> <key>OSBundleProductName</key> <string>UAD-1 Powered Plug-Ins</string> <key>OSBundleProductURL</key> <string>http://www.uaudio.com</string> </dict> </plist>
Mais nulle part je trouve un cas de figure semblable au miens.
Pour rappel mon soucis est que mon Lecteur XML ne récupère plus la valeur si celle-ci à son double identique, sinon si son double est différent là sa marche.
Merci
Partager