0

I have used code from link for parsing xml it worked in versions less than android 2.3 but I am trying to get it done 4.0.3 it doesn't return any value in it at all.How solve this issue.I dont get any errors in the log but I dont get the parsed values as output.Here is the link I used as code

@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;

}
Markus Jarderot
  • 86,735
  • 21
  • 136
  • 138
Karthik
  • 4,943
  • 19
  • 53
  • 86

1 Answers1

1

Use Log.e() instead of System.out.println(). You are probably getting an exception, but it isn't shown.

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;
}

(where TAG is a string-constant)

Markus Jarderot
  • 86,735
  • 21
  • 136
  • 138
  • Nope its the same,it didnt do anything in catch part. – Karthik Jul 25 '12 at 07:29
  • Then I don't know. [`DocumentBuilder.parse()`](http://www.docjar.com/html/api/org/apache/xerces/jaxp/DocumentBuilderImpl.java.html) should never return `null`. (Assuming Xerces is the implementation used. Check which implementation is used with `db.getClass().getName()`. ) – Markus Jarderot Jul 25 '12 at 07:48