1

嘿,伙计们,我想在 android 上显示艺术家信息,所以我尝试解析 xml,但是在艺术家摘要之前有像这样“CDATA”这样的奇怪标签,所以当我运行我的代码时,我得到空白文本视图,我尝试使用 Json,但它超出了我的编写json解析的能力

这是我的代码

 String URL = "http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Cher&api_key=b25b959554ed76058ac220b7b2e0a026&limit=" + 1 + "&page=" + 1;
        XmlParser parser = new XmlParser();
        String xml = parser.getXmlFromUrl(URL); // getting XML
        Document doc = parser.getDomElement(xml); // getting DOM element
                            NodeList nl = doc.getElementsByTagName("artist");
             for (i = 0; i < nl.getLength(); i++) 
             {
                    Element e = (Element) nl.item(i);
                     name = parser.getValue(e, KEY_NAME);// name child value
                        image = parser.getValue(e, KEY_IMAGE);
                        summary = parser.getValue(e, KEY_Summary);
                                            return summary;
        } 
            return null;
    }
            @Override
    protected void onPostExecute(String result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);
                    URL thumb_u;
            try {
                thumb_u = new URL(result);
                  Drawable thumb_d = Drawable.createFromStream(thumb_u.openStream(), "src");
                  tv.setText(result);//textview text set
                    icon.setImageDrawable(thumb_d);
4

1 回答 1

0

从哪里来XmlParser?我用谷歌搜索,我猜它来自这里?如果是这样,改变

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

将此行添加到getDomElement

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setCoalescing(true);

文档:setCoalescing

于 2012-09-24T16:57:54.013 回答