错误:无法解析方法getElementsByTagName

时间:2015-10-17 18:58:48

标签: android xml android-studio

我正在尝试在android中创建一个xmlparser,我正在关注这个Tutorial

我收到此错误“无法解析方法getElementsByTagName”这里我做错了什么是我的代码

package com.example.zeus.contactapplication;

import android.provider.DocumentsContract;
import android.renderscript.Element;
import android.util.Log;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import java.io.IOException;
import java.io.StringReader;
import java.io.UnsupportedEncodingException;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

/**
 * Created by ZEUS on 10/17/2015.
 */
public class xmlPasrser {

    //This function is ujsed to get  an xml response from a url
    public  String getxmlfromURL(String url)
    {
        String xml = "";

        try {
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpost = new HttpPost(url);

            HttpResponse httpresponse = httpClient.execute(httpost);
            HttpEntity httpentity = httpresponse.getEntity();
            xml = EntityUtils.toString(httpentity);
        }catch (UnsupportedEncodingException e){

            Log.d("LOL",e.getMessage());
        }
        catch (ClientProtocolException e){

            Log.d("LOL",e.getMessage());
        }
        catch (IOException e){

            Log.d("LOL",e.getMessage());
        }

        return xml;
    }

 //this will be used to getDOM from the cml
    public Document getdomElement(String xml)
    {
        Document doc = null;
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

        try {
            DocumentBuilder db = dbf.newDocumentBuilder();

            InputSource is = new InputSource();
            is.setCharacterStream(new StringReader((xml)));
            doc = db.parse(is);

        } catch (ParserConfigurationException e) {
            Log.d("LOL", e.getMessage());
            return null;
        } catch (SAXException e) {
            Log.d("LOL", e.getMessage());
            return null;
        } catch (IOException e) {
            Log.d("LOL", e.getMessage());
            return null;
        }

        return  doc;
    }

    public String getValue(Element item, String str)
    {
        NodeList n = item.getElementsByTagName(str);
    }

}

我的代码有什么问题或者这里的教程错了吗? 感谢名单

0 个答案:

没有答案