1

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

字符串过滤器="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= 过滤器的节点。即 type = Abcd 的所有元素。非常感谢任何帮助。

谢谢, 席德

4

0 回答 0