I have some existing code that parses the namespace of the top-level elements to determine which XML file we are looking for.
XMLEventReader reader = createXMLEventReader(...); try { while (reader.hasNext()) { XMLEvent event = reader.nextEvent(); switch (event.getEventType()) { case XMLStreamConstants.DTD: // No particularly useful information here? //((DTD) event).getDocumentTypeDeclaraion(); break; case XMLStreamConstants.START_ELEMENT: formatInfo.qName = ((StartElement) event).getName(); return formatInfo; default: break; } } } finally { reader.close(); }
If I allow the parser to download DTDs from the Internet, getDocumentTypeDeclaraion() contains a giant string with more information than I know how to deal with it, because it inserts all the associated DTDs into the string before passing it. On the other hand, if I block the parser downloading the DTD from the Internet (which is preferable anyway, for obvious reasons), it gives me the line, "<!DOCTYPE" .
Is there no way to return values ββinside a DOCTYPE?
I use the default parser that comes with the JRE, in case that matters.
source share