下面是我相信可以幫助到你想要什麼樣:
private void loadXML(Reader reader) throws ParserConfigurationException, SAXException {
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setValidating(true);
SAXParser parser = parserFactory.newSAXParser();
parser.parse(new InputSource(reader), new MyHandler());
}
private static class MyHandler
extends DefaultHandler {
private static final String PREFS_DTD_URI = "http://www.example.com/dtd/document.dtd";
public InputSource resolveEntity(String publicId, String systemId) throws SAXException {
if (systemId.equals(PREFS_DTD_URI)) {
InputSource is = new InputSource(new StringReader(PREFS_DTD)); // PREFS_DTD is a string containing actual DTD, any other Reader could be here
is.setSystemId(PREFS_DTD_URI);
return is;
}
// else use the default behaviour
return null;
}
}
parserFactory.setValidating(真);行在android中給出Parserconfigurationexception,並給出警告,說明不支持驗證的實現。它在java中工作,但不在android中。有沒有其他的方法可以在android中進行dtd驗證? –
@Mdroid,對不起,可能我錯過了「android」標籤。這個問題本身並沒有說它是關於android平臺的。你解決了這個問題嗎? –
對不起,我沒有問題提到「Android平臺」。目前我沒有更多的工作。 –