CDATA解析java文件xml

时间:2015-05-18 08:57:26

标签: android parsing

嗨,我有这个代码用于解析:

这是文件xml我需要解析白色CDATA: < [CDATA [! Ue,via libera alla Missione navale Contro Gli scafisti:Comando all'Italia ]>

public class MainActivity extends Activity {
    // Declare Variables
    ListView listview;
    ListViewAdapter adapter;
    ProgressDialog mProgressDialog;
    ArrayList<HashMap<String, String>> arraylist;
    static String RANK = "title";
    static String COUNTRY = "description";
    static String POPULATION = "pubDate";
    static String FLAG = "link";




    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Get the view from listview_main.xml
        setContentView(R.layout.listview_main);
        // Execute DownloadJSON AsyncTask
        new DownloadXML().execute();
    }

    // DownloadJSON AsyncTask
    private class DownloadXML extends AsyncTask<Void, Void, Void> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            // Create a progressdialog
            mProgressDialog = new ProgressDialog(MainActivity.this);
            // Set progressdialog title
            mProgressDialog.setTitle("Android XML Parse Tutorial");
            // Set progressdialog message
            mProgressDialog.setMessage("Loading...");
            mProgressDialog.setIndeterminate(false);
            // Show progressdialog
            mProgressDialog.show();
        }

        @Override
        protected Void doInBackground(Void... params) {
            // Create an array
            arraylist = new ArrayList<HashMap<String, String>>();

            XMLParser parser = new XMLParser();
            // Retrieve nodes from the given URL address
            String xml = parser
                    .getXmlFromUrl("http://www.aduc.it/generale/files/feed/avvertenze_rss.xml");
            // Retrive DOM element
            Document doc = parser.getDomElement(xml);

            try {
                // Identify the element tag name
                NodeList nl = doc.getElementsByTagName("item");
                for (int i = 0; i < nl.getLength(); i++) {
                    // creating new HashMap
                    HashMap<String, String> map = new HashMap<String, String>();
                    Element e = (Element) nl.item(i);
                    // adding each child node to HashMap key => value
                    map.put(RANK, parser.getValue(e, RANK));
                    map.put(COUNTRY, parser.getValue(e, COUNTRY));
                    map.put(POPULATION, parser.getValue(e, POPULATION));
                    map.put(FLAG, parser.getValue(e, FLAG));
                    // adding HashList to ArrayList
                    arraylist.add(map);
                }
            } catch (Exception e) {
                Log.e("Error", e.getMessage());
                e.printStackTrace();
            }
            return null;
        }

这是文件xml我需要解析白色CDATA: &lt; [CDATA [! Ue,via libera alla Missione navale Contro Gli scafisti:Comando all'Italia ]&GT;   

0 个答案:

没有答案