-
Bug
-
Resolution: Unresolved
-
P4
-
None
-
6
-
x86
-
windows_xp
FULL PRODUCT VERSION :
java version "1.6.0_10"
Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
Java HotSpot(TM) Client VM (build 11.0-b15, mixed mode, sharing)
java version "1.6.0_11"
Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
Linux localhost 2.6.27-7-server #1 SMP Tue Nov 4 20:18:35 UTC 2008 i686 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
DTD.getDocumentTypeDeclaration() returns the complete contents of the DTD and the XML document and a bunch of junk characters, instead of the actual doctype declaration.
If the DTD cannot be resolved, it returns "<!-- Exception scanning External DTD Subset. True contents of DTD cannot be determined. Processing will continue as XMLInputFactory.IS_VALIDATING == false. -->"
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the sample code below
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
--- DTD ---
<!DOCTYPE package PUBLIC "+//abc//123//EN" "foo.dtd" []>
--- DTD ---
--- DTD ---
<!DOCTYPE package PUBLIC "+//ISBN 0-262-21013-4//DTD OEB 1.0.1 Package//EN" "http://openebook.org/dtds/oeb-1.0.1/oebpkg101.dtd" []>
--- DTD ---
ACTUAL -
(see attachment output.txt)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.IOException;
import java.io.StringReader;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.DTD;
import javax.xml.stream.events.XMLEvent;
public class DtdBug {
public static void main(String[] args) throws IOException, XMLStreamException {
XMLInputFactory factory = XMLInputFactory.newInstance();
factory.setProperty(XMLInputFactory.SUPPORT_DTD, true);
factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true);
factory.setProperty(XMLInputFactory.IS_VALIDATING, false);
String xmlDocument = "<?xml version=\"1.0\"?>\n" +
"<!DOCTYPE package PUBLIC \"+//abc//123//EN\" \"foo.dtd\">\n" +
"<package>\n" +
"</package>\n";
String xmlDocument2 = "<?xml version=\"1.0\"?>\n" +
"<!DOCTYPE package PUBLIC \"+//ISBN 0-262-21013-4//DTD OEB 1.0.1 Package//EN\" \"http://openebook.org/dtds/oeb-1.0.1/oebpkg101.dtd\">\n" +
"<package>\n" +
"</package>\n";
XMLEventReader reader = factory.createXMLEventReader(new StringReader(xmlDocument));
while(reader.hasNext()) {
XMLEvent event = reader.nextEvent();
if(event instanceof DTD) {
DTD dtd = (DTD)event;
System.out.println("--- DTD ---");
System.out.println(dtd.getDocumentTypeDeclaration());
System.out.println("--- DTD ---");
}
}
reader = factory.createXMLEventReader(new StringReader(xmlDocument2));
while(reader.hasNext()) {
XMLEvent event = reader.nextEvent();
if(event instanceof DTD) {
DTD dtd = (DTD)event;
System.out.println("--- DTD ---");
System.out.println(dtd.getDocumentTypeDeclaration());
System.out.println("--- DTD ---");
}
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Woodstox implementation fixes this, although that's not exactly a work around.
java version "1.6.0_10"
Java(TM) SE Runtime Environment (build 1.6.0_10-b33)
Java HotSpot(TM) Client VM (build 11.0-b15, mixed mode, sharing)
java version "1.6.0_11"
Java(TM) SE Runtime Environment (build 1.6.0_11-b03)
Java HotSpot(TM) Client VM (build 11.0-b16, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
Linux localhost 2.6.27-7-server #1 SMP Tue Nov 4 20:18:35 UTC 2008 i686 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
DTD.getDocumentTypeDeclaration() returns the complete contents of the DTD and the XML document and a bunch of junk characters, instead of the actual doctype declaration.
If the DTD cannot be resolved, it returns "<!-- Exception scanning External DTD Subset. True contents of DTD cannot be determined. Processing will continue as XMLInputFactory.IS_VALIDATING == false. -->"
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the sample code below
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
--- DTD ---
<!DOCTYPE package PUBLIC "+//abc//123//EN" "foo.dtd" []>
--- DTD ---
--- DTD ---
<!DOCTYPE package PUBLIC "+//ISBN 0-262-21013-4//DTD OEB 1.0.1 Package//EN" "http://openebook.org/dtds/oeb-1.0.1/oebpkg101.dtd" []>
--- DTD ---
ACTUAL -
(see attachment output.txt)
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.io.IOException;
import java.io.StringReader;
import javax.xml.stream.XMLEventReader;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.events.DTD;
import javax.xml.stream.events.XMLEvent;
public class DtdBug {
public static void main(String[] args) throws IOException, XMLStreamException {
XMLInputFactory factory = XMLInputFactory.newInstance();
factory.setProperty(XMLInputFactory.SUPPORT_DTD, true);
factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true);
factory.setProperty(XMLInputFactory.IS_VALIDATING, false);
String xmlDocument = "<?xml version=\"1.0\"?>\n" +
"<!DOCTYPE package PUBLIC \"+//abc//123//EN\" \"foo.dtd\">\n" +
"<package>\n" +
"</package>\n";
String xmlDocument2 = "<?xml version=\"1.0\"?>\n" +
"<!DOCTYPE package PUBLIC \"+//ISBN 0-262-21013-4//DTD OEB 1.0.1 Package//EN\" \"http://openebook.org/dtds/oeb-1.0.1/oebpkg101.dtd\">\n" +
"<package>\n" +
"</package>\n";
XMLEventReader reader = factory.createXMLEventReader(new StringReader(xmlDocument));
while(reader.hasNext()) {
XMLEvent event = reader.nextEvent();
if(event instanceof DTD) {
DTD dtd = (DTD)event;
System.out.println("--- DTD ---");
System.out.println(dtd.getDocumentTypeDeclaration());
System.out.println("--- DTD ---");
}
}
reader = factory.createXMLEventReader(new StringReader(xmlDocument2));
while(reader.hasNext()) {
XMLEvent event = reader.nextEvent();
if(event instanceof DTD) {
DTD dtd = (DTD)event;
System.out.println("--- DTD ---");
System.out.println(dtd.getDocumentTypeDeclaration());
System.out.println("--- DTD ---");
}
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Woodstox implementation fixes this, although that's not exactly a work around.