【问题标题】:How to decode &lt;br&gt; in Java [duplicate]如何在Java中解码<br> [重复]
【发布时间】:2015-05-25 07:22:54
【问题描述】:

在网站http://web.mta.info/status/serviceStatus.txt 中,一些标签被编码,例如&amp;lt;br&amp;gt;。我想知道如何将这些标签解码回它们的正常格式,以便我可以解析并阅读它们。下面的代码是我目前拥有的。

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 基本上是通过文件找到我需要的信息。

【问题讨论】:

标签: java android xml-parsing html-parsing


【解决方案1】:

替换

&amp;lt; 与 &gt; 与 >

&amp;lt; 代表 &amp;gt; 代表 >

那些 html 实体留在您提到的网站的代码 sn-p 中,主要是由于一个错误,这就是该网站逃避代码 sn-ps 的方式。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-01
    • 2011-09-25
    • 1970-01-01
    • 1970-01-01
    • 2021-04-27
    相关资源
    最近更新 更多