Je la vois pas ton image, hostingpics.net est bloqué par le firewall de mon boulot... Mets la plutôt en pièce jointe de ton message
Version imprimable
j'ai le même soucie de caractère avec cette nouvelle commande
mon illustration en pj
Pièce jointe 72407
Apparemment c'est du ISO-8859-1 interprété à tort comme de l'UTF-8... tu es sûr que ça marche pas en passant l'Encoding en paramètre du StreamReader ?
En tous cas c'est quand même bizarre que le fichier soit encodé en ISO alors que la déclaration XML indique UTF-8 :?Code:
1
2
3
4 Dim doc As New XmlDocument() Using reader As New StreamReader(pathXml, System.Text.Encoding.Default) doc.Load(reader) End Using
Ca y est c'est bon ! :D
C'est le second paramètre du steamreader qui me faisait défaut, j'ai pris ton code et l'ai passé en System.Text.Encoding.UTF8
Donc voila tout fonctionne, un grand merci à vous tomlev et chrismonoye, vous m'avez enlevé une belle épine du pied :ccool:
Donc a charge de revanche, si je peus vous renvoyer l'ascenseur n'hésitez pas ;) (mon domaine de compétence c'est l'admin de parc info, et le dév web)
P.S : je ne met pas encore la discussion a résolu , je vais nettoyer un peu mon code et le poster ici bas
Donc ci-dessous le résultat de mes recherches et de l'aide conséquente de tomlev et chrismonoye.
La fonction ci-dessous est assez spécifiques, mais elle contient bon nombre de petites choses précieuses car assez rare a trouvé sur la toile.
Pour vous mettre dans le contexte, j'ai réalisé cette fonction afin de parcourir un XML que je ne pouvais modifié, ayant une structure assez complexe et un nombre de champs et de ligne variable.
Bon ce code n'est surement pas le mieux structuré ni le plus optimisé, mais je n'ai pas vraiment le temps de le reprendre, de plus si je le met ici c'est afin de mettre a disposition des exemples de code ;)
Tout d'abord le xml que je cherche a lire :
(je vous avais dis qu'il était assez complexe)Code:
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117 <?xml version="1.0" encoding="UTF-8"?> <office:document-content xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:presentation="urn:oasis:names:tc:opendocument:xmlns:presentation:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0" xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0" xmlns:math="http://www.w3.org/1998/Math/MathML" xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0" xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:oooc="http://openoffice.org/2004/calc" xmlns:dom="http://www.w3.org/2001/xml-events" xmlns:xforms="http://www.w3.org/2002/xforms" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rpt="http://openoffice.org/2005/report" xmlns:of="urn:oasis:names:tc:opendocument:xmlns:of:1.2" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:grddl="http://www.w3.org/2003/g/data-view#" xmlns:field="urn:openoffice:names:experimental:ooo-ms-interop:xmlns:field:1.0" xmlns:rdfa="http://docs.oasis-open.org/opendocument/meta/rdfa#" office:version="1.2" grddl:transformation="http://docs.oasis-open.org/office/1.2/xslt/odf2rdf.xsl"> <office:scripts/> <office:font-face-decls> <style:font-face style:name="Arial" svg:font-family="Arial" style:font-family-generic="swiss" style:font-pitch="variable"/> <style:font-face style:name="Andale Sans UI" svg:font-family="'Andale Sans UI'" style:font-family-generic="system" style:font-pitch="variable"/> <style:font-face style:name="Arial Unicode MS" svg:font-family="'Arial Unicode MS'" style:font-family-generic="system" style:font-pitch="variable"/> <style:font-face style:name="Tahoma" svg:font-family="Tahoma" style:font-family-generic="system" style:font-pitch="variable"/> </office:font-face-decls> <office:automatic-styles> <style:style style:name="co1" style:family="table-column"> <style:table-column-properties fo:break-before="auto" style:column-width="2.267cm"/> </style:style> <style:style style:name="co2" style:family="table-column"> <style:table-column-properties fo:break-before="auto" style:column-width="3.528cm"/> </style:style> <style:style style:name="ro1" style:family="table-row"> <style:table-row-properties style:row-height="0.453cm" fo:break-before="auto" style:use-optimal-row-height="true"/> </style:style> <style:style style:name="ta1" style:family="table" style:master-page-name="Default"> <style:table-properties table:display="true" style:writing-mode="lr-tb"/> </style:style> <number:date-style style:name="N37" number:automatic-order="true"> <number:day number:style="long"/> <number:text>/</number:text> <number:month number:style="long"/> <number:text>/</number:text><number:year/> </number:date-style> <style:style style:name="ce1" style:family="table-cell" style:parent-style-name="Default" style:data-style-name="N37"/> <style:style style:name="ta_extref" style:family="table"> <style:table-properties table:display="false"/> </style:style> </office:automatic-styles> <office:body> <office:spreadsheet> <table:table table:name="Sheet1" table:style-name="ta1" table:print="false"> <table:table-column table:style-name="co1" table:number-columns-repeated="3" table:default-cell-style-name="Default"/> <table:table-column table:style-name="co2" table:default-cell-style-name="ce1"/> <table:table-row table:style-name="ro1"> <table:table-cell office:value-type="string"> <text:p>NOM</text:p> </table:table-cell> <table:table-cell office:value-type="string"> <text:p>PRENOM</text:p> </table:table-cell> <table:table-cell office:value-type="string"> <text:p>CLASSE</text:p> </table:table-cell> <table:table-cell table:style-name="Default" office:value-type="string"> <text:p>DATE_NAISSANCE</text:p> </table:table-cell> </table:table-row> <table:table-row table:style-name="ro1"> <table:table-cell office:value-type="string"> <text:p>DUPOND</text:p> </table:table-cell> <table:table-cell office:value-type="string"> <text:p>Albert</text:p> </table:table-cell> <table:table-cell office:value-type="string"> <text:p>3émeA</text:p> </table:table-cell> <table:table-cell office:value-type="date" office:date-value="1982-03-23"> <text:p>23/03/82</text:p> </table:table-cell> </table:table-row> <table:table-row table:style-name="ro1"> <table:table-cell office:value-type="string"><text:p>DURAND</text:p></table:table-cell> <table:table-cell office:value-type="string"><text:p>Didier</text:p></table:table-cell> <table:table-cell office:value-type="string"><text:p>4émeC</text:p></table:table-cell> <table:table-cell office:value-type="date" office:date-value="1412-04-01"><text:p>23/03/12</text:p></table:table-cell> </table:table-row> <table:table-row table:style-name="ro1"> <table:table-cell office:value-type="string"><text:p>LAPOINTE</text:p></table:table-cell> <table:table-cell office:value-type="string"><text:p>Boby</text:p></table:table-cell> <table:table-cell office:value-type="string"><text:p>5émeB</text:p></table:table-cell> <table:table-cell office:value-type="date" office:date-value="2010-09-14"><text:p>14/09/10</text:p></table:table-cell> </table:table-row> <table:table-row table:style-name="ro1"> <table:table-cell office:value-type="string"><text:p>MOSBY</text:p></table:table-cell> <table:table-cell office:value-type="string"><text:p>Ted</text:p></table:table-cell> <table:table-cell office:value-type="string"><text:p>6émeD</text:p></table:table-cell> <table:table-cell office:value-type="date" office:date-value="2045-11-21"><text:p>21/11/45</text:p></table:table-cell> </table:table-row> </table:table> <table:table table:name="Sheet2" table:style-name="ta1" table:print="false"> <table:table-column table:style-name="co1" table:default-cell-style-name="Default"/> <table:table-row table:style-name="ro1"><table:table-cell/></table:table-row> </table:table> <table:table table:name="Sheet3" table:style-name="ta1" table:print="false"> <table:table-column table:style-name="co1" table:default-cell-style-name="Default"/> <table:table-row table:style-name="ro1"><table:table-cell/></table:table-row> </table:table> </office:spreadsheet> </office:body> </office:document-content>
et la fonction dont je me sers pour le parcourir :
et voila ! Have Fun :mrgreen:Code:
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 ''' <summary> ''' ReturnDataXml ''' </summary> ''' <param name="pathXml">chemin jusqu'au fichier que vous souhaité lire ex : c:\toto\content.xml</param> ''' <remarks></remarks> Private Sub ReturnDataXml(ByVal pathXml As String) Try '' DECOMPTE DU NB DE VALEUR PAR LIGNE ' pour mes besoins , il me faut compté le nombre de résultat sur la premiére ligne Dim doc As New XmlDocument() Dim mgr As New XmlNamespaceManager(New NameTable()) ' ces 3 lignes permettent de définir l'encodage, sans ca les caractéres spéciaux n'apparaissent pas correctement Using reader As New StreamReader(pathXml, System.Text.Encoding.UTF8) doc.Load(reader) End Using ' déclaration des namespace, bon alors pour info un namespace c'est le préfixe de la balise, en l'occurence je déclare office table et text car c'est ceux que dont je vais avoir besoin mgr.AddNamespace("office", "urn:oasis:names:tc:opendocument:xmlns:office:1.0") mgr.AddNamespace("table", "urn:oasis:names:tc:opendocument:xmlns:table:1.0") mgr.AddNamespace("text", "urn:oasis:names:tc:opendocument:xmlns:text:1.0") ' défini l'arborescence de mon xml qui me ménera jusqu'au noeud voulue Dim row As XmlElement = CType(doc.SelectSingleNode("/office:document-content/office:body/office:spreadsheet/table:table/table:table-row", mgr), XmlElement) ' définition du noeud qui contient l'info que je souhaite récupéré Dim nombreChamp As Integer = row.GetElementsByTagName("text:p").Count '' PARCOURS DES VALEURS Dim XmlDoc As New XmlDocument() Dim element As XmlNodeList Dim numLigne As Integer = 1 Dim numCol As Integer = 1 ' ces 3 lignes permettent de définir l'encodage, sans ca les caractéres spéciaux n'apparaissent pas correctement Using reader2 As New StreamReader(pathXml, System.Text.Encoding.UTF8) XmlDoc.Load(reader2) End Using ' définition du noeud qui contient l'info que je souhaite récupéré element = XmlDoc.DocumentElement.GetElementsByTagName("text:p") ' on parcours tous les noeuds text:p For Each noeud In element 'j'avais besoin de connaitre les "coordonnées" de mes données affichés If numCol = nombreChamp + 1 Then numLigne = numLigne + 1 numCol = 1 End If ' affichage de mes données MsgBox("Numéro Colonne " & numCol & vbCrLf & "Numéro Ligne " & numLigne & vbCrLf & "Valeur " & noeud.innertext()) numCol = numCol + 1 Next Catch ex As Exception MsgBox(ex.Message) End Try End Sub