0

您好我正在尝试从 url 解析 XML 文件,我的 NodeList 包含值,但每个节点的 getNodeValue 都返回 null。有谁能够帮我?

这是我解析xml的方法。

public ArrayList xmloku(String url) {

        ArrayList xmllistesi = new ArrayList();

        try {

            URL xmlyolu = new URL(url);
            DocumentBuilderFactory dFactory = DocumentBuilderFactory
                    .newInstance();
            DocumentBuilder dBuilder = dFactory.newDocumentBuilder();

            Document document = dBuilder.parse(new InputSource(xmlyolu
                    .openStream()));
            document.getDocumentElement().normalize();

            NodeList nodeListCountry = document
                    .getElementsByTagName("karikatur");

            for (int i = konum; i < nodeListCountry.getLength(); i++) {
                Node node = nodeListCountry.item(i);
                Element elementMain = (Element) node;
                xmllistesi.add(elementMain.getNodeValue());
                     }
4

1 回答 1

0

而不是getNodeValue()尝试使用getTextContent()

for (int i = konum; i < nodeListCountry.getLength(); i++) {
    Node node = nodeListCountry.item(i);
    Element elementMain = (Element) node;
    xmllistesi.add(elementMain.getTextContent());
}
于 2013-10-02T20:55:45.050 回答