2012-04-20 20 views
0

xmlファイルから情報を取得しようとしていますが、別のリンクを試しましたが、動作しますが、このurl = "http://www.w3schools.com/xml/simple.xml"それはSAXExceptionの ここではxmlを使用して解析する

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)をキャッチ は誰もが私はこの問題を回避することができますどのように助けることができますキャッチ?

答えて

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"); 
関連する問題