RE: [android-developers] how to reduce xml parsing time

2010-06-02 Thread Ted Neward
Use a StAX parser instead of a DOM parser. StAX will let you look at the
elements in order, but without having to read the entire thing into memory
at once and then navigate the hierarchy.

I can't remember if there's a StAX parser in Android (it was included as
part of 1.4 or Java 5, I can't remember which), but there's a reference
implementation from BEA floating out on the Web someplace, should be a snap
to grab it and include it as a library (worst case).

Ted Neward
Java, .NET, XML Services
Consulting, Teaching, Speaking, Writing
http://www.tedneward.com

> -Original Message-
> From: android-developers@googlegroups.com [mailto:android-
> develop...@googlegroups.com] On Behalf Of Er. syed imran ali
> Sent: Tuesday, June 01, 2010 11:56 PM
> To: Android Developers
> Cc: imran...@gmail.com
> Subject: [android-developers] how to reduce xml parsing time
> 
> hi all,
> in my application i have to read xml from web-service,
> it is working fine, but major problem is it is taking more
> time to parse data, though same data is taking less time on
> iPhone and Blackberry. i have similar code on blackberry it is
> taking less time to parse. is any fast parsing process in Android?
> if any body know kindly reply me.
> my code simple is as follow.
> 
>  DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
>DocumentBuilder db = dbf.newDocumentBuilder();
>doc = db.parse(in);
> NodeList nodes = doc.getElementsByTagName("Member");
>  if(nodes.getLength() > 0){
> 
>   for (int i = 0; i < nodes.getLength(); i++) {
>   Member mem = new Member();
> 
>   Element memelement = (Element)
> nodes.item(i);
> 
>   NodeList member =
> memelement.getElementsByTagName("MemberID");
>   Element memberText = (Element)
> member.item(0);
>   String  MemberID =
> getCharacterDataFromElement(memberText);
>   mem.setMemberID(MemberID);
> 
>   member =
> memelement.getElementsByTagName("FirstName");
>   memberText = (Element) member.item(0);
> 
> mem.setFirstName(getCharacterDataFromElement(memberText));
> 
>   member =
> memelement.getElementsByTagName("LastName");
>   memberText = (Element) member.item(0);
> 
> mem.setLastName(getCharacterDataFromElement(memberText));
> 
>   member =
> memelement.getElementsByTagName("MailingAddress1");
>   memberText = (Element) member.item(0);
> 
> mem.setMailingAddress1(getCharacterDataFromElement(memberText));
>   ...
>   ...
>   ...
>   }
> Thanks and regards
> Syed Imran ali
> 
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-
> develop...@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] how to reduce xml parsing time

2010-06-02 Thread Indrajit Kumar

On 6/2/2010 12:25 PM, Er. syed imran ali wrote:

entBuilder db = dbf.newDocumentBuilder();
doc = db.parse(in);
NodeList nodes = doc.getElementsByTagName("Member");
  if(nodes.getLength()>  0){

for (int i = 0; i<  nodes.getLength(); i++) {


Hey buddy,
For XML Parsing use Pull Parser instead of DOM Parsing.
A DOM parser works by parsing a XML file into a native data structure 
matching the hierarchy of the XML file and the entire file is looked up 
so it uses more memory while a pull parser works by creating a loop that 
continually requests the next event and can then handle that event 
directly within the loop. The best part of the pull parser is that it 
can easily be stopped at any point. only do processing on demand and 
remove the overhead of extra method calls and classes.


--
Technology never Ends, Learn Fast...

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en