You are much more likely to find someone willing to "check it for you"
if you tell us what you think is wrong with it: after all, we don't
have a sample of XML handy that is consistent with the XML parser
events you expect. We are not likely to reverse engineer your parser
to come up with a sample. Do you get an Exception when you run this?
Tell us what it is. Do you not get events when you expect them? Then
we need to know what events you expect when. Do you even know that the
parser is doing an in order depth first traversal of the parse tree?
Where are you expecting to find the tree when the parse is done?

In fact, looking at your code, the most prominent thing I see missing
is that all your many Log.e() statements do not log what exception is
thrown. Now to be sure, that will find its way into logcat anyway, but
at least the name of the Exception should be in the Log.e() statement,
so that you can look in logcat and line it up with the exception
thrown.

Finally, though the article is quite dated, 
http://www.javaworld.com/jw-03-2000/jw-03-xmlsax.html
is still an excellent, free online source for how to use SAX to parse
XML. It also includes references to other excellent sources, such as
http://www.javaworld.com/javaworld/jw-04-1999/jw-04-xml.html

One of the first things I think of when glancing back at those
article, for example, is that I don't see your implementation of the
ContentHandler interface. See the articles for details (though it is
old enough to still use the deprecated DocumentHanlder instead).
Without that, you are throwing away the parse tree you construct.

On Jul 20, 10:39 pm, minh <[email protected]> wrote:
> Hi everyone.
> I try to parser XML file using SAX parser. Can you help me.?
> Above is some line code i think it not correct. Someone can check for
> me, please:
>
> try{
>                 SAXParserFactory spf = SAXParserFactory.newInstance();
>                 SAXParser sp = spf.newSAXParser();
>                 xmlHandler myXMLHandler = new xmlHandler();
>                 try{
>                         File fxml = new File("/mnt/sdcard/myXML.xml");
>                         fxml.getName(); // test file null
>                         try{
>                                 sp.parse(fxml,myXMLHandler);
>                         }catch (Exception e) {
>                                         // TODO: handle exception
>                                 Log.e("ERROR","Can not parser file 
> xml"+e.toString());
>                                 }
>                 }catch (Exception e) {
>                                 // TODO: handle exception
>                         Log.e("ERROR","Can not new file xml from source");
>                         }
>
>                 /** Get result from MyXMLHandler ebook Object */
>                 ebook = xmlHandler.getEbook();
>
>                 /** Create handler to handle XML Tags ( extends
> DefaultHandler ) */
>
>         }catch (Exception e) {
>                         // TODO: handle exception
>                 Log.e("ERROR","Error parser file");
>                 }
>         try{
>                 String author= ebook.getAuthor();
>                 EditText txtEdit = (EditText) findViewById(R.id.editText1);
>                 txtEdit.setText(author);
>         }catch (Exception e) {
>                         // TODO: handle exception
>                 Log.e("ERROR","Ebook can not get author");
>                 }
>     }

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

Reply via email to