【发布时间】:2015-05-25 07:22:54
【问题描述】:
在网站http://web.mta.info/status/serviceStatus.txt 中,一些标签被编码,例如<br>。我想知道如何将这些标签解码回它们的正常格式,以便我可以解析并阅读它们。下面的代码是我目前拥有的。
String address = "http://web.mta.info/status/serviceStatus.txt";
XmlPullParserFactory pullParserFactory;
XmlPullParser parser;
HttpClient httpclient;
HttpGet httpget;
URI website;
HttpResponse response;
HttpEntity httpEntity;
InputStream xmlFile;
//code that just initializes some other variables
private void updater() {
// try catch to catch any exceptions thrown
try {
httpclient = new DefaultHttpClient();
httpget = new HttpGet(address);
response = httpclient.execute(httpget);
httpEntity = response.getEntity();
xmlFile = httpEntity.getContent();
pullParserFactory = XmlPullParserFactory.newInstance();
parser = pullParserFactory.newPullParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
parser.setInput(xmlFile, null);
parseXML(parser);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
parseXML 基本上是通过文件找到我需要的信息。
【问题讨论】:
-
您需要一个实体引用,例如w3.org/2003/entities/2007/w3centities-f.ent。我在 C# 中做到了这一点,但不是在 Java 中。
标签: java android xml-parsing html-parsing