开发者

Problem with parsing xml from a string in Android

开发者 https://www.devze.com 2023-01-28 08:18 出处:网络
I want to parse an XML from a string. This is working fine when the str开发者_运维知识库ing length is small. But for a long string it is not parsing anything. It is suspended on calling parse(). I use

I want to parse an XML from a string. This is working fine when the str开发者_运维知识库ing length is small. But for a long string it is not parsing anything. It is suspended on calling parse(). I use the following code for parsing. Please tell me what is the wrong with my code?

        //my xml code is string 'xmlString'
         DocumentBuilderFactory objDocFactory=DocumentBuilderFactory.newInstance();
         DocumentBuilder objDocBuilder=objDocFactory.newDocumentBuilder();  
         InputSource objInput=new InputSource();
         objInput.setCharacterStream(new StringReader(xmlString));
         Document objDoc=objDocBuilder.parse(objInput);
         //appication is suspended at the above line
         objDoc.getDocumentElement().normalize();

Thank you...


How large is the document?

I have used TinyXML parser for Android, and am pretty satisfied with the result. Maybe you can check it out once.

Best part is it is pretty ease to use, and the learning curve is considerably less.


Exactly what Keith said. Using DOM it's trying to load the entire document into memory, which is not the best thing on a mobile device. SAX will stream the data so it will only use a little memory.

0

精彩评论

暂无评论...
验证码 换一张
取 消