Android XmlPullParser Check IsEndElement(XmlPullParser reader, String name)

Here you can find the source of IsEndElement(XmlPullParser reader, String name)

Description

Is End Element

License

Open Source License

Declaration

public static boolean IsEndElement(XmlPullParser reader, String name)
            throws XmlPullParserException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

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

public class Main {
    public static boolean IsEndElement(XmlPullParser reader)
            throws XmlPullParserException {
        if (reader == null)
            throw new NullPointerException();
        return IsEndElement(reader, null);
    }//from  w  ww  . j a  v a  2  s.c o  m

    public static boolean IsEndElement(XmlPullParser reader, String name)
            throws XmlPullParserException {
        if (reader == null)
            throw new NullPointerException();
        return (reader.getEventType() == XmlPullParser.END_TAG)
                && (isNullOrEmpty(name) || StringEquals(
                        GetFullName(reader), name));
    }

    public static boolean IsEndElement(XmlPullParser reader,
            String namespaceName, String localName)
            throws XmlPullParserException {
        if (reader == null)
            throw new NullPointerException();
        return (reader.getEventType() == XmlPullParser.END_TAG)
                && IsName(reader, namespaceName, localName);
    }

    private static boolean isNullOrEmpty(String s) {
        return s == null || s.length() == 0;
    }

    private static boolean StringEquals(String s1, String s2) {
        if (s1 == s2)
            return true;
        if (s1 == null || s2 == null)
            return false;
        return s1.equals(s2);
    }

    public static String GetFullName(XmlPullParser reader) {
        if (reader.getPrefix() != null)
            return reader.getPrefix() + ":" + reader.getName();
        return reader.getName();
    }

    public static boolean IsName(XmlPullParser reader,
            String namespaceName, String localName) {
        if (reader == null)
            throw new NullPointerException();
        String ns = reader.getNamespace();
        if (isNullOrEmpty(ns)) {
            ns = null;
        }
        if (isNullOrEmpty(namespaceName)) {
            namespaceName = null;
        }
        return (StringEquals(ns, namespaceName))
                && (isNullOrEmpty(localName) || StringEquals(
                        reader.getName(), localName));
    }
}

Related

  1. IsElement(XmlPullParser reader)
  2. IsElement(XmlPullParser reader, String name)
  3. IsElement(XmlPullParser reader, String namespaceName, String localName)
  4. IsEndElement(XmlPullParser reader)
  5. IsEndElement(XmlPullParser reader, String namespaceName, String localName)
  6. IsName(XmlPullParser reader, String namespaceName, String localName)
  7. IsStartElement(XmlPullParser reader)
  8. IsStartElement(XmlPullParser reader, String name)