Android XmlPullParser Value Get getAttributes( XmlPullParser pullParser)

Here you can find the source of getAttributes( XmlPullParser pullParser)

Description

get Attributes

License

Apache License

Declaration

private static Map<String, String> getAttributes(
            XmlPullParser pullParser) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.IOException;

import java.util.HashMap;
import java.util.Map;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.text.TextUtils;

public class Main {

    public static Map<String, String> getAttributes(
            XmlPullParser pullParser, String namespace, String elementName,
            String attributeName, String attributeValue)
            throws XmlPullParserException, IOException {
        Map<String, String> attributes = null;
        boolean shouldEndParse = false;
        if (pullParser != null) {
            if (!TextUtils.isEmpty(elementName)) {
                int event = pullParser.getEventType();
                while (event != XmlPullParser.END_DOCUMENT
                        && !shouldEndParse) {
                    switch (event) {
                    case XmlPullParser.START_TAG:
                        if (elementName.equals(pullParser.getName())) {
                            //                     VolleyLog.d("parsing tag is %s", pullParser.getName());
                            if (!TextUtils.isEmpty(attributeName)
                                    && !TextUtils.isEmpty(attributeValue)) {
                                // VolleyLog.d("attributeName %s",attributeName);
                                // VolleyLog.d("attributeValue %s",attributeValue);
                                if (attributeValue.equals(pullParser
                                        .getAttributeValue(namespace,
                                                attributeName))) {
                                    //                           VolleyLog.d("finded the suit element");
                                    attributes = getAttributes(pullParser);
                                    shouldEndParse = true;
                                }//from ww  w.  j  a  v  a 2 s .  co  m
                            } else {
                                attributes = getAttributes(pullParser);
                                shouldEndParse = true;
                            }
                        }
                        break;
                    }
                    event = pullParser.next();
                }
            }
        }
        return attributes;
    }

    private static Map<String, String> getAttributes(
            XmlPullParser pullParser) {
        Map<String, String> attributes = new HashMap<String, String>(
                pullParser.getAttributeCount());
        for (int i = 0; i < pullParser.getAttributeCount(); i++) {
            attributes.put(pullParser.getAttributeName(i),
                    pullParser.getAttributeValue(i));
        }
        return attributes;
    }
}

Related

  1. getAttributeByName(XmlPullParser xpp, String name)
  2. getAttributeValue(XmlPullParser pp, String name)
  3. getAttributeValue(XmlPullParser pp, String name)
  4. getAttributes( XmlPullParser pullParser, String namespace, String elementName, String attributeName, String attributeValue)
  5. getPIData(XmlPullParser pp)
  6. getPIData(XmlPullParser pp)
  7. getPITarget(XmlPullParser pp)