bonjour tout le monde

je veux parser un simple document xml

document xml: test.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
<?xml version="1.0"?>
 
 
<liens>
 
<video>rtsp://10.0.2.2/fichierTest.sdp</video>
 
 
<slides>http://10.0.2.2/imageTest.jpg</slides>
 
 
</liens>
l'activité:
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
package org.anddev.android.parsingxml;
 
import java.net.URL;
 
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
 
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
 
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
 
public class ParsingXML extends Activity {
 
     private final String MY_DEBUG_TAG = "WeatherForcaster";
 
     /** Called when the activity is first created. */
     @Override
     public void onCreate(Bundle icicle) {
          super.onCreate(icicle);
 
          /* Create a new TextView to display the parsingresult later. */
          TextView tv = new TextView(this);
          try {
               /* Create a URL we want to load some xml-data from. */
               URL url = new URL("http://10.0.2.2/test.xml");
 
               /* Get a SAXParser from the SAXPArserFactory. */
               SAXParserFactory spf = SAXParserFactory.newInstance();
               SAXParser sp = spf.newSAXParser();
 
               /* Get the XMLReader of the SAXParser we created. */
               XMLReader xr = sp.getXMLReader();
               /* Create a new ContentHandler and apply it to the XML-Reader*/
               ExampleHandler myExampleHandler = new ExampleHandler();
               xr.setContentHandler(myExampleHandler);
 
               /* Parse the xml-data from our URL. */
               xr.parse(new InputSource(url.openStream()));
               /* Parsing has finished. */
 
               /* Our ExampleHandler now provides the parsed data to us. */
               ParsedExampleDataSet parsedExampleDataSet = myExampleHandler.getParsedData();
 
               /* Set the result to be displayed in our GUI. */
               tv.setText(parsedExampleDataSet.toString());
 
          } catch (Exception e) {
               /* Display any Error to the GUI. */
               tv.setText("Error: " + e.getMessage());
               Log.e(MY_DEBUG_TAG, "WeatherQueryError", e);
          }
          /* Display the TextView. */
          this.setContentView(tv);
     }
}
le gestionnaire:
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
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
package org.anddev.android.parsingxml;
 
 
 
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
 
 
 
 
public class ExampleHandler extends DefaultHandler{
 
     // ===========================================================
     // Fields
     // ===========================================================
 
     private boolean in_liens = false;
     private boolean in_video = false;
     private boolean in_slides = false;
 
 
 
 
 
 
     private ParsedExampleDataSet myParsedExampleDataSet = new ParsedExampleDataSet();
 
     // ===========================================================
     // Getter & Setter
     // ===========================================================
 
     public ParsedExampleDataSet getParsedData() {
          return this.myParsedExampleDataSet;
     }
 
     // ===========================================================
     // Methods
     // ===========================================================
     @Override
     public void startDocument() throws SAXException {
          this.myParsedExampleDataSet = new ParsedExampleDataSet();
     }
 
     @Override
     public void endDocument() throws SAXException {
          // Nothing to do
     }
 
 
     /** Gets be called on opening tags like:
      * <tag>
      * Can provide attribute(s), when xml was like:
      * <tag attribute="attributeValue">*/
     @Override
     public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
 
    	 if (localName.equals("liens")) {
               this.in_liens = true;
 
          }else if (localName.equals("video")) {
               this.in_video = true;
 
          }else if (localName.equals("slides")) {
               this.in_slides = true;
          }
 
     }
 
     /** Gets be called on closing tags like:
      * </tag> */
     @Override
     public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
          if (localName.equals("liens")) {
               this.in_liens = false;
 
          }else if (localName.equals("video")) {
 
 
               this.in_video = false;
 
          }else if (localName.equals("slides")) {
 
               this.in_slides = false;
 
          }
 
     }
 
     /** Gets be called on the following structure:
      * <tag>characters</tag> */
     @Override
    public void characters(char ch[], int start, int length) {
 
    	 if(this.in_video){
             myParsedExampleDataSet.setVideo(new String(ch, start, length));
             }
             if(this.in_slides){
             myParsedExampleDataSet.setSlides(new String(ch, start, length));
             }  
 
 
 
 
    }
}
le retour du parseur:
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
package org.anddev.android.parsingxml;
 
public class ParsedExampleDataSet {
 
 
	private String video, slides;
 
 
	 public String getVideo(){return video;}
	 public String getSlides() {return slides;}
 
	 public void setVideo(String video){this.video=video;}
	 public void setSlides(String slides){this.slides=slides;}
 
	  public String toString(){
		  return "video = "+this.video + "\n slides = "+ this.slides;
	  }
 
}
le résultat affiché
le log:
04-23 09:54:54.062: ERROR/WeatherForcaster(357): WeatherQueryError
04-23 09:54:54.062: ERROR/WeatherForcaster(357): java.io.FileNotFoundException: http://10.0.2.2/test.xml
04-23 09:54:54.062: ERROR/WeatherForcaster(357): at org.apache.harmony.luni.internal.net.http://www.protocol.http.HttpURLConn...tion.java:1061)
04-23 09:54:54.062: ERROR/WeatherForcaster(357): at java.net.URL.openStream(URL.java:653)
04-23 09:54:54.062: ERROR/WeatherForcaster(357): at org.anddev.android.parsingxml.ParsingXML.onCreate(ParsingXML.java:42)
04-23 09:54:54.062: ERROR/WeatherForcaster(357): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-23 09:54:54.062: ERROR/WeatherForcaster(357): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
04-23 09:54:54.062: ERROR/WeatherForcaster(357): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
04-23 09:54:54.062: ERROR/WeatherForcaster(357): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
04-23 09:54:54.062: ERROR/WeatherForcaster(357): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
04-23 09:54:54.062: ERROR/WeatherForcaster(357): at android.os.Handler.dispatchMessage(Handler.java:99)
04-23 09:54:54.062: ERROR/WeatherForcaster(357): at android.os.Looper.loop(Looper.java:123)
04-23 09:54:54.062: ERROR/WeatherForcaster(357): at android.app.ActivityThread.main(ActivityThread.java:4363)
04-23 09:54:54.062: ERROR/WeatherForcaster(357): at java.lang.reflect.Method.invokeNative(Native Method)
04-23 09:54:54.062: ERROR/WeatherForcaster(357): at java.lang.reflect.Method.invoke(Method.java:521)
04-23 09:54:54.062: ERROR/WeatherForcaster(357): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
04-23 09:54:54.062: ERROR/WeatherForcaster(357): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
04-23 09:54:54.062: ERROR/WeatherForcaster(357): at dalvik.system.NativeStart.main(Native Met
je mentionne que l'erreur est à la ligne:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
 xr.parse(new InputSource(url.openStream()));
de la classe ParsingXML

merci d'avance pour tout aide