Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6846133

StAX XMLEventReader DTD issues

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 6u11
    • xml
    • h1170
    • generic
    • generic
    • Verified

        OPERATING SYSTEM
        ----------------
        Windows

        FULL JDK VERSION
        ----------------
        1.6.0_11

        DESCRIPTION
        -----------
        I'm using the StAX XMLEventReader to read a DTD declaration. When running on the Sun JRE, I'm
        observing two problems:

        1. The Sun parser attempts to resolve the DTD, even though
           IS_SUPPORTING_EXTERNAL_ENTITIES is explicitly set to false.

        2. The call to ((javax.xml.stream.events.DTD)event).getDocumentTypeDeclaration ())
           will return a useless truncated value.

        Attached is DTDTest.java which will replicate this problem every time.

        TESTCASE SOURCE
        ---------------
        import javax.xml.stream.XMLStreamException;

        public class DTDTest {
            private static final String xml = "<!DOCTYPE html PUBLIC \"-//W3C//DTDXHTML 1.0 Transitional//EN\" "
                                              + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"
                                              + "<html><body><p>I am some simple html</p></body> </html>";

            public static void main (String[] args) throws Exception {
                javax.xml.stream.XMLInputFactory factory = javax.xml.stream.XMLInputFactory.newInstance ();
                factory.setXMLResolver (new DTDResolver ());
                factory.setProperty (javax.xml.stream.XMLInputFactory.SUPPORT_DTD, true);
                factory.setProperty (javax.xml.stream.XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES , false);
                java.io.ByteArrayInputStream is = new java.io.ByteArrayInputStream(xml.getBytes ("UTF-8"));
                javax.xml.transform.stream.StreamSource source = new javax.xml.transform.stream.StreamSource (is);
                javax.xml.stream.XMLEventReader reader = factory.createXMLEventReader (source);
                while (reader.hasNext ()) {
                    javax.xml.stream.events.XMLEvent event = reader.nextEvent ();
                    if (event.getEventType () == javax.xml.stream.XMLStreamConstants.DTD)
                        System.out.println (((javax.xml.stream.events.DTD) event).getDocumentTypeDeclaration ());
                }
            }
        }

        class DTDResolver implements javax.xml.stream.XMLResolver {
            public Object resolveEntity (String arg0, String arg1, String arg2, String arg3) throws XMLStreamException
            {
                System.out.println ("I should never be called");
                return new java.io.ByteArrayInputStream (new byte[0]);
            }
        }

              joehw Joe Wang
              dkorbel David Korbel (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: