如何在Hashmap中过滤数据

时间:2013-09-06 20:06:48

标签: java android hashmap

我有一个名为filter my class的字符串,它是预先填充的。

String filter =“Abcd”;

现在我有以下代码从外部XML读取数据。

NodeList quizList = doc.getElementsByTagName("QuizData");

        HashMap<String, String> map = null;

        for (int i = 0; i < quizList.getLength(); i++) {

            map = new HashMap<String, String>();

            Node firstQuestionNode = quizList.item(i);

            if (firstQuestionNode.getNodeType() == Node.ELEMENT_NODE) {

                Element firstAircraftElement = (Element) firstQuestionNode;
                // 1.-------
                NodeList idList = firstAircraftElement
                        .getElementsByTagName(KEY_ID);
                Element firstIdElement = (Element) idList.item(0);
                NodeList textIdList = firstIdElement.getChildNodes();
                // --id
                map.put(KEY_ID, textIdList.item(0).getNodeValue().trim());

                // 2.-------
                NodeList typeList = firstAircraftElement
                        .getElementsByTagName(KEY_TYPE);
                Element firstTypeElement = (Element) typeList.item(0);
                NodeList textTypeList = firstTypeElement.getChildNodes();
                // --type
                map.put(KEY_TYPE, textTypeList.item(0).getNodeValue()
                        .trim());

                // 3.-------
                NodeList quesList = firstAircraftElement
                        .getElementsByTagName(KEY_QUES);
                Element firstQuesElement = (Element) quesList.item(0);
                NodeList textQuesList = firstQuesElement.getChildNodes();
                // -- Question
                map.put(KEY_QUES, textQuesList.item(0).getNodeValue()
                        .trim());

                // Add to the Arraylist
                quizDataCollection.add(map);
            }
        }

现在我想只过滤那些有KEY_TYPE = filter的节点。即type = Abcd的所有元素。任何帮助都非常感谢。

谢谢, SID

0 个答案:

没有答案