Question

I've read some examples but that didn't help me with my particular case.

I've got book.xml which has tags like :

<BOOK name="hereGoesName">
<CHAPTER number="1">
<LINE number="1">

etc...

so, after reading examples I made a test code :

XmlPullParser xpp;
xpp = getResources().getXml(R.xml.book);
int i=0;int chapter=3;
    try {
        while (i<chapter){ //chapter is the number of chapter I seek
            if (xpp.getEventType()==XmlPullParser.START_TAG && xpp.getName()=="CHAPTER" ) {i++; Log.d("MyLog","seeked chapter i="+i);}
        xpp.next();
        }

So, by this I try to count third tag named CHAPTER, but executing this code halts my phone forever. Which means that either my code is wrong or it is right but CHAPTER tag couldn't be found.

But if I place Log.d("MyLog", xpp.getName()); - it shows me exactly CHAPTER as a tag.

Please, anyone solve this to me and, more importantly, how can I search not for CHAPTER only but for example, <CHAPTER number="3"> if xpp.getName() is simply CHAPTER?

Was it helpful?

Solution

Use xpp.getName().equals("CHAPTER") instead of xpp.getName()=="CHAPTER"

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top