Bonjour,
je souhaite parser un fichier xml en Csharp. Je suis passé par Xpath.
Mais voilà, j'ai un problème, il ne va pas sur le noeud que je demande mais il me renvoi toutes les données du xml.
Apparement le problème vient du xmlns="http://earth.google.com/kml/2.2"
si j'enlève ça tout fonctionne.
Voilà le fichier xml
et mon codeCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 <?xml version="1.0" encoding="UTF-8"?> <kml xmlns="http://earth.google.com/kml/2.2"> <Placemark> <name>The Track</name> <Style> <LineStyle> <color>ff00ffff</color> <width>2</width> </LineStyle> <PolyStyle> <color>7f00ff00</color> </PolyStyle> </Style> <LineString> <extrude>1</extrude> <tessellate>1</tessellate> <altitudeMode>absolute</altitudeMode> <coordinates>2.58084,49.00925666666671,169.5 2.58093333333333,49.00916,158.2</coordinates> </LineString> </Placemark> </kml>
Quelqu'un sait pourquoi?Code:
1
2
3
4
5
6
7 XPathDocument kml_file = new XPathDocument("trajet.kml"); XPathNavigator xPathNav = kml_file.CreateNavigator(); XPathNodeIterator xit = xPathNav.Select("descendant::coordinates"); xit.MoveNext(); Console.WriteLine(xit.Current.Value);