0

xml ファイルから情報を取得しようとしていますが、別のリンクを試してみましたが、動作しますが、この url="http://www.w3schools.com/xml/simple.xml" を渡すと、SAXexception がキャッチされます。コード

public class XMLfunctions {

    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.e("Error: ", e.getMessage());
                return null;
            } catch (SAXException e) {
                Log.e("Error: ", e.getMessage());
                return null;
            } catch (IOException e) {
                Log.e("Error: ", e.getMessage());
                return null;
            }
                // return DOM
            return doc;
    }

それは(SAXException e)をキャッチしますこの問題を回避する方法を誰か助けてもらえますか??

4

1 に答える 1

0

これを使って

 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
 DocumentBuilder db = dbf.newDocumentBuilder();
 Document doc = db.parse(new InputSource(new StringReader(response)));
// normalize the document
doc.getDocumentElement().normalize();
 // get the root node
NodeList nodeList = doc.getElementsByTagName("your tag name");
于 2012-04-20T16:36:48.267 に答える