XMLPULL源码解读记录 方法解读parseEndTag

a、解析过程中遇到

b、代码详解

    public int parseEndTag() throws XmlPullParserException, IOException {
        //ASSUMPTION ch is past "'
        //紧接在 must match start tag name <"+startname+">"
                    +" from line "+elRawNameLine[depth], this, null);
        }
        //如果与startTag的元素名称不完全相同,抛异常
        for (int i = 0; i < len; i++)
        {
            if(buf[off++] != cbuf[i]) {
                // construct strings for exception
                final String startname = new String(cbuf, 0, len);
                final String endname = new String(buf, off - i - 1, len);
                throw new XmlPullParserException(
                    "end tag name  must be the same as start tag <"+startname+">"
                        +" from line "+elRawNameLine[depth], this, null);
            }
        }

        //忽略元素名称结尾部分空字符
        while(isS(ch)) { ch = more(); } // skip additional white spaces
        //没有>紧随则抛出异常
        if(ch != '>') {
            throw new XmlPullParserException(
                "expected > to finish end tag not "+printable(ch)
                    +" from line "+elRawNameLine[depth], this, null);
        }

        //namespaceEnd = elNamespaceCount[ depth ]; //FIXME
        posEnd = pos;
        pastEndTag = true;
        return eventType = END_TAG;
    }

 

c、代码要点

c.1、第一个字符必须符合isNameStartChar()条件。xml规范中大多有这个要求,名称后面出现空格等空白字符是允许的。

c.2、解析元素名称,检查与startTag对应元素名称是否一致。

c.3、紧接元素名称后,是否有>字符收尾。

c.4、返回END_TAG事件。

你可能感兴趣的:(XMPP)