Android: why use XMLReader?

Is there a reason why I should use XMLReader with SAXParser? I see this usage quite a lot:

        sp = spf.newSAXParser();
        XMLReader xr = sp.getXMLReader();
        LoginContentHandler uch = new LoginContentHandler();
        xr.setContentHandler(uch);
        xr.parse(new InputSource(in));

I always use the parser this way:

        sp = spf.newSAXParser();
        DefaultHandler dh = new LoginContentHandler();
        sp.parse(in, dh);

Any specific reason? Just interesting because my path is shorter and I really don't understand why I should use XMLReader.

+5
source share
1 answer

to answer the question.

People using XMLReader assume that there is enough memory to store the file as a tree object, and it can go through it in Log (n) to search.

, SAX straight , , , n , .

.

SAX:

+5

All Articles