Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/180.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android SaxHandler格式不正确错误_Android_Xml_Saxparser_Saxparseexception - Fatal编程技术网

Android SaxHandler格式不正确错误

Android SaxHandler格式不正确错误,android,xml,saxparser,saxparseexception,Android,Xml,Saxparser,Saxparseexception,我正在使用SaxHandler解析来自第三方应用程序的日志文件。我的代码: public class SaxHandler extends DefaultHandler { private String tempVal; private String response; private boolean readResponse; boolean elementOn; public SaxHandler() { readResponse = false; elementOn =

我正在使用SaxHandler解析来自第三方应用程序的日志文件。我的代码:

public class SaxHandler extends DefaultHandler {

private String tempVal;
private String response;
private boolean readResponse;
boolean elementOn;

public SaxHandler() {
    readResponse = false;
    elementOn = false;
}

@Override
public void startElement(String uri, String localName,
        String qName, Attributes attributes) throws SAXException {

    if (qName.equalsIgnoreCase("method") || qName.equalsIgnoreCase("message")) {
        elementOn = true;
    }
}

@Override
public void endElement(String uri, String localName, String qName)
        throws SAXException {
    if (qName.equalsIgnoreCase("message")) {
        if (readResponse) {
            response        = tempVal;
            readResponse    = false;
        }
    }
    if (qName.equalsIgnoreCase("method")) {
        if (tempVal.equalsIgnoreCase("postHtml")) {
            readResponse = true;
        }
    }
}

@Override
public void characters(char[] ch, int start, int length)
        throws SAXException {

    if (elementOn) {
        tempVal = new String(ch, start, length);
        elementOn = false;
    }

}

public String getLastResponse() {
    return response;
}
} 
日志文件中的示例记录:

<record>
<date>07.07.2014 16:12:45</date>
<millis>1404735165155</millis>
<sequence>12</sequence>
<logger>logName</logger>
<level>FINER</level>
<class>ru.tsi.maksbm.android.revise.ReviseStartActivity</class>
<method>onStart</method>
<thread>0</thread>
<message>Starting ReviseStartActivity</message>
</record>

为什么解析器没有将此行识别为单个字符串?

您的字符实现是错误的。处理程序可以为同一标记多次调用此回调。除此之外,我看不出你的工作有什么大问题code@blackbelt在这种情况下,我如何才能确定解析器是用1个标记完成的?它是在调用endElement时完成的
 <message>action=%D0%92%D1%85%D0%BE%D0%B4&j_username=U_USER&password=hash&</message>
"The reference to entity "j_username" must end with the ';' delimiter"