documentbuilderfactory not workining in android 3.0
This is the code which I was using for android 2.3 . and it use to work properly. But don no why it doesn't seem to work in android 3.0
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
开发者_StackOverflow try
{
try
{
while(this.xml.available()>0)
Log.e("content", ""+this.xml.read());
}
catch (Exception e) {
// TODO: handle exception
Log.e("error", "while reading the file");
}
this.xml.reset();
DocumentBuilder builder = factory.newDocumentBuilder();
Document dom = builder.parse(this.xml);
Element root = dom.getDocumentElement();
Log.d(TAG, "have root?"+dom.getLocalName());;
Log.d(TAG, "have root?"+dom.getInputEncoding());;
Log.d(TAG, "have root?"+dom.getNodeValue());;
}
catch (Exception e)
{
Log.e(TAG, e.getMessage(), e);
}
//Log.d(TAG, "Exit: parse");
return stores;
}
The innner while displays the file contents in numbers. But when I get the dom.* I get null why is it so ?
Any suggetions ?
Actually there were some bugs in DOM for android releases before Android 3.0 These bugs are corrected in 3.0 so there might be some changes required in the older implementations done by you using DOM
please refer to this link
http://code.google.com/p/android/issues/detail?id=2735#c11
Cheers HImanshu
Don't use Element root = dom.getDocumentElement();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document dom = builder.parse(stream);
NodeList nodeResponse = dom.getElementsByTagName("rootelement");
seems the way the element are accessed are a bit different now.
For others check out the new ways of writing it.
Thanks
精彩评论