2012-07-25 2 views
0

xml을 파싱하기위한 링크에서 코드를 사용했습니다. 안드로이드 2.3 이하 버전에서 작동했지만 4.0.3에서 모든 값을 반환하지 않습니다.이 문제점을 해결합니다. 알지 못합니다. output.Here가 link I used as codeAndroid 4.0에서 지원되는 XML을 구문 분석하는 방법은 무엇입니까?

@SuppressWarnings("unused") 
public final static Document XMLfromString(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) { 
     System.out.println("XML parse error: " + e.getMessage()); 
     return null; 
    } catch (SAXException e) { 
     System.out.println("Wrong XML file structure: " + e.getMessage()); 
     return null; 
    } catch (IOException e) { 
     System.out.println("I/O exeption: " + e.getMessage()); 
     return null; 
    } 

    return doc; 

} 

답변

1

사용 Log.e() 대신 System.out.println()이기 때문에 내가 그나마 어떤 로그에 오류하지만 구문 분석 된 값을 얻는다. 아마 예외가 발생하지만 표시되지 않습니다.

try { 
    ... 
} catch (ParserConfigurationException e) { 
    Log.e(TAG, "XML parse error", e); 
    return null; 
} catch (SAXException e) { 
    Log.e(TAG, "Wrong XML file structure", e); 
    return null; 
} catch (IOException e) { 
    Log.e(TAG, "I/O exeption", e); 
    return null; 
} 

(TAG이 어디 문자열 상수)

+0

이 아니 그 같은, 그것은 캐치 부분에 아무것도 할 didnt한다. – Karthik

+0

그럼 나도 몰라. ['DocumentBuilder.parse()'] (http://www.docjar.com/html/api/org/apache/xerces/jaxp/DocumentBuilderImpl.java.html)는 절대로'null '을 반환해서는 안됩니다. (Xerces가 사용 된 구현이라고 가정하면,'db.getClass(). getName()'에서 어떤 구현이 사용되는지 확인하십시오.) –

관련 문제