本文介绍了WARN / ExpatReader(222):DTD处理程序不支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的SAXParser解析从服务器接收到的XML数据。
我创建了抽象XMLParser类扩展了DefaultHandler与抽象方法字符()的startElement()的endElement()我也遇到过这个问题(WARN / ExpatReader(718):DTD处理程序不支持)。我解析停在middle.I提到提出了一些答案,按照以下code
我的code

I am using SAXParser for parsing the xml data received from server.I have created the abstract class XmlParser extends DefaultHandler with abstract methods characters(),startelement(),endelement().I have encountered this issue(WARN/ExpatReader(718): DTD handlers aren't supported.)My PArsing stops in the middle.I have referred some answers suggested to follow the below codeMy code

public abstract class XmlParser extends DefaultHandler {

public XmlParser(final String xmlData) {
    parseDocument(xmlData);
}

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

@Override
public abstract void endElement(String uri, String localName, String qName)
    throws SAXException;

private void parseDocument(final String xmlData) {
    SAXParserFactory spf = SAXParserFactory.newInstance();

    try {
        SAXParser sp = spf.newSAXParser();
        InputStream is = new ByteArrayInputStream(xmlData.getBytes("UTF-8"));<----I think i have to change here
        sp.parse(is, this);
    } catch (SAXException ex) {
        ex.printStackTrace();
    } catch (ParserConfigurationException ex) {
        ex.printStackTrace();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

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

}

简称答案

的XMLReader的XMLReader = SAXParserFactory.newInstance()newSAXParser()getXMLReader()。
xmlReader.setContentHandler(// YourHandler延伸的DefaultHandler);
xmlReader.parse(新的InputSource(// BufferedReader类));

XMLReader xmlReader = SAXParserFactory.newInstance().newSAXParser().getXMLReader();xmlReader.setContentHandler(//YourHandler extends DefaultHandler);xmlReader.parse(new InputSource(//BufferedReader));

我的问题
我有一个扩展的DefaultHandler的抽象类。
我不能创建一个对象,它在setContentHandler通过()方法。
我应该记住这XmlParser的是抽象的,因为我已经覆盖每个模块解析器
所以建议我一个解决方案,以解决这个问题。

problem for mei have an abstract class that extends defaulthandler.I cant create a object for it to pass in setContentHandler() method.I should keep this XmlParser as abstract since i have to override for each module parserSo suggest me a solution to overcome this issue

推荐答案

这是一个的。据报道固定在升级Froyo(2.2)。

This is a known bug. It was reported as fixed in FroYo (2.2).

这篇关于WARN / ExpatReader(222):DTD处理程序不支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 15:47