Bonjour à tous,
Voilà j'ai un petit problème, je n'arrive pas à parcourir un fichier XML venant d'un webservice.

Voici mon code :

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
public string Lecture (string elevation){
 
            // Create a request using a URL that can receive a post. 
            WebRequest request = WebRequest.Create(elevation);
            // Set the Method property of the request to POST.
            request.Method = "POST";
            // Create POST data and convert it to a byte array.
            string postData = "This is a test that posts this string to a Web server.";
            byte[] byteArray = Encoding.UTF8.GetBytes(postData);
            // Set the ContentType property of the WebRequest.
            request.ContentType = "application/x-www-form-urlencoded";
            // Set the ContentLength property of the WebRequest.
            request.ContentLength = byteArray.Length;
            // Get the request stream.
            Stream dataStream = request.GetRequestStream();
            // Write the data to the request stream.
            dataStream.Write(byteArray, 0, byteArray.Length);
            // Close the Stream object.
            dataStream.Close();
            // Get the response.
            WebResponse response = request.GetResponse();
            // Get the stream containing content returned by the server.
            dataStream = response.GetResponseStream();
            // Open the stream using a StreamReader for easy access.
            StreamReader reader = new StreamReader(dataStream);
            // Read the content.
            string responseFromServer = reader.ReadToEnd();
 
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseFromServer);
            XmlNode donnees;
            XmlElement root = xmlDoc.DocumentElement;
            donnees = root.SelectSingleNode("descendant::result[elevation]");
 
 
            alt = donnees.ToString();
            // Clean up the streams.
            reader.Close();
            //dataStream.Close();
            response.Close();
 
            return alt;
        }

Je récupère donc de mon Webservice une string du type XML:

<ElevationResponse>
<status>OK</status>
<result>
<location>
<lat>45.4504618</lat>
<lng>4.3970448</lng>
</location>
<elevation>492.3283081</elevation>
</result>
</ElevationResponse>
Ensuite, je parcours mon fichier et retourne l'altitude pour pouvoir le mettre dans un autre fichier XML.

Suite à l'éxécution de mon script, ceci me renvoi la valeur :
System.Xml.XmlElement

Est-ce que quelqu'un pourrait m'expliquer l'erreur que j'ai faite et comment y remédier

Merci d'avance.

Cordialement