我发现很多人有这个问题,但找不到任何答案。我从url读取xml,它是有效的,包含xml头声明。 我做错了什么?
这是我的代码:
String data = "";
InputStream iStream = null;
URL url = new URL(strUrl);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.connect();
iStream = urlConnection.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(iStream));
StringBuffer sb = new StringBuffer();
String line = "";
while( ( line = br.readLine()) != null){
sb.append(line);
}
data = sb.toString();
StringReader reader = new StringReader(data);
XmlPullParser parser = Xml.newPullParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
parser.setInput(reader);
parser.nextTag();
这是我的xml:
<organizations>
<organization name="ps" private="true" flag="http://wptrafficanalyzer.in/p/demo1/india.png"><country>US</country><city city="New York" />
<OrganizationID >12</OrganizationID>
</organization>
</organizations>