Help in sax2 xmlpull parser

                 <OfficeDepot label="OD" version="7">
                        <word32 label="Zip" value="7220"/>
                        <word32 label="Street" value="1934"/>
                        <word32 label="Type" value="341"/>
                        <word32 label="Count" value="400"/>
                        <word32 label="Open" value="145"/>
                  </<OfficeDepot >

How can I extract the value of count in this xml string.
In the start tag event I am able to idetify Officedepot as a tag. How do I traverse down and get the  value for count
Thanks for all the help
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.


package sax;


import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;

public class SimpleXmlPullApp {

      public static void main(String args[]) throws XmlPullParserException,
                  IOException {
            XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
            XmlPullParser xpp = factory.newPullParser();

            String input = "<OfficeDepot label=\"OD\" version=\"7\">"
                        + "<word32 label=\"Zip\" value=\"7220\"/>"
                        + "<word32 label=\"Street\" value=\"1934\"/>"
                        + "<word32 label=\"Type\" value=\"341\"/>"
                        + "<word32 label=\"Count\" value=\"400\"/>"
                        + "<word32 label=\"Open\" value=\"145\"/>" + "</OfficeDepot>";
            xpp.setInput(new StringReader(input));
            int eventType = xpp.getEventType();
            String count = null;
            while (count == null && eventType != XmlPullParser.END_DOCUMENT) {
                  if (eventType == XmlPullParser.START_TAG) {
                        if ("word32".equals(xpp.getName())) {
                              String label = xpp.getAttributeValue(null, "label");
                              if ("Count".equals(label)) {
                                    count = xpp.getAttributeValue(null, "value");
                  eventType =;
            if (count != null) {
                  System.out.printf("count=%s\n", count);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mayank SAssociate Director - Product EngineeringCommented:
CEHJ, is that somebody's homework done :) ?

You can also use XPath, BTW.
I hope not - i would guess that pull-parsing's not very 'homeworky'
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Mayank SAssociate Director - Product EngineeringCommented:
pull = null, I know ;-)
prgeorge3383Author Commented:
I was just stuck , I was thinking start tag  event is genetated , only when it hits the OfficeDepot  label....
prgeorge3383Author Commented:
How do i make sure the officedepot label is the parent
Please post a new question - only one allowed per thread (see site rules)
prgeorge3383Author Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.