0

这是我的 Http 响应

 <p><b>Most Recent Vehicle Details and Test Summary applicable to this test number.</b></p>
       <dl>
        <dt>
         <span><b>Registration mark:</b></span>
        </dt>
        <dd>
         <b>DU06BFZ</b>
        </dd>
       </dl>
       <dl>
        <dt>
         <span>Make/Model:</span>
        </dt>
        <dd>
         TOYOTA / COROLLA VERSO
        </dd>
       </dl>
       <dl>
        <dt>
         <span>Colour:</span>
        </dt>
        <dd>
         SILVER
        </dd>
       </dl>
       <dl>
        <dt>
         <span>VIN/Chassis No:</span>
        </dt>
        <dd>
         NMTEA16R60R017458
        </dd>
       </dl>
       <dl>
        <dt>
         <span>Approximate date of first use:</span>
        </dt>
        <dd>
         01/03/2006
        </dd>
       </dl>
       <dl>
        <dt>
         <span>Type of fuel:</span>
        </dt>
        <dd>
         Diesel
        </dd>
       </dl>&nbsp;
       <hr />
       <dl>
        <dt>
         <span><b>Date of test:</b></span>
        </dt>
        <dd>
         <b>15/03/2013</b>
        </dd>
       </dl>
       <p><b>Certificate issued (Pass)</b></p>
       <dl>
        <dt>
         <span>Odometer reading:</span>
        </dt>
        <dd>
         67,885 Miles
        </dd>
       </dl>
       <dl>
        <dt>
         <span>Test number:</span>
        </dt>
        <dd>
         435294573022
        </dd>
       </dl>

这是我的代码,用于显示<dd>仅在标签中的内容。

document = Jsoup.parse(result);
Element ele = document.select("dt:contains(Registration mark:) ~dd").get(0);

**Logs**

    09-13 15:06:26.506: I/System.out(1351): <dd>
09-13 15:06:26.506: I/System.out(1351):  <b>DU06BFZ</b>
09-13 15:06:26.506: I/System.out(1351): </dd>
09-13 15:06:26.936: I/System.out(1351): <dd>
09-13 15:06:26.936: I/System.out(1351):  SILVER
09-13 15:06:26.936: I/System.out(1351): </dd>

这里想<dd><b></b></dd>从响应中删除那些。怎么做。

4

1 回答 1

0

此功能将读取您的标签并打印到 logcat

public void xmlParse(String result) throws XmlPullParserException, IOException {
        Log.i("String", "going in xml parse");
        boolean demoflag = false;

        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(true);
        XmlPullParser xpp = factory.newPullParser();

        xpp.setInput(new StringReader(result));
        int eventType = xpp.getEventType();

        while (eventType != XmlPullParser.END_DOCUMENT) {
            switch (eventType) {
            case XmlPullParser.START_DOCUMENT:
                break;

            case XmlPullParser.START_TAG:
                if (xpp.getName().equalsIgnoreCase("dd")) {
                    demoflag = true;
                }
                break;
            case XmlPullParser.TEXT:
                if (demoflag) {
                    Log.i("dd", "" + xpp.getText().trim());
                }
                break;
            case XmlPullParser.END_TAG:
                if (xpp.getName().equalsIgnoreCase("dd")) {
                    demoflag = false;
                }
                break;
            default:
                break;
            }

            eventType = xpp.next();
        }

    }
于 2013-09-13T09:46:45.600 回答