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

org.w3c.dom.Node.setPrefix(String prefix) throws incorrect DOMException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 1.4.0
    • 6
    • xml
    • 1.4
    • generic
    • windows_xp
    • Verified

        The problem can be reproducible using the jdk 6.
        According to the spec for org.w3c.dom.Node.setPrefix(String prefix):
        "
        void setPrefix(String prefix)
                       throws DOMException
        NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
        NAMESPACE_ERR: Raised if the specified prefix is malformed per the Namespaces in XML specification, if the namespaceURI of this node is null, if the specified prefix is "xml" and the namespaceURI of this node is different from " http://www.w3.org/XML/1998/namespace", if this node is an attribute and the specified prefix is "xmlns" and the namespaceURI of this node is different from "http://www.w3.org/2000/xmlns/", or if this node is an attribute and the qualifiedName of this node is "xmlns" [XML Namespaces] .
        "

        In the following code example, it calls Node.setPrefix(String) on an read-only Entity node. The test expects the method to throw DOMException.NO_MODIFICATION_ALLOWED_ERR
        but on jdk 6, it throws DOMException.NAMESPACE_ERR instead.

        See the code example below:
        =============================================================
        import org.xml.sax.InputSource;
        import java.io.StringReader;

        public class MyDomTest2 {

           public static void main(String[] args) {

            String data =
                "<?xml version=\"1.0\" ?>"
                + "<!DOCTYPE test:root ["
                + "<!ELEMENT test:root ANY>"
               + "<!ENTITY ent \"foo\">"
                + "<!ATTLIST test:root test:a CDATA #FIXED \"qqq\">"
                + "]>"
                + "<test:root xmlns:test=\"http://xxxx.xx/\">"
                + "</test:root>";
                          
            Document document = null;
            try {
                DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance()
                                                     .newDocumentBuilder();
                document = docBuilder.parse(new InputSource(new StringReader(data)));
            } catch (ParserConfigurationException e) {
                System.out.println(e.toString());
            } catch (IOException e) {
                System.out.println(e.toString());
            } catch (SAXException e) {
                System.out.println(e.toString());
            }
                
            Entity anEntity = (Entity)document.getDoctype().getEntities().item(0);
            try {
                anEntity.setPrefix("test1");
                
                System.out.println("Should throw DOMException.");
            } catch(DOMException e) {
                if (e.code == DOMException.NO_MODIFICATION_ALLOWED_ERR) {
                    System.out.println("OK");
                } else {
                    System.out.println("should throw DOMException.NO_MODIFICATION_ALLOWED_ERR (7). The error returned is " + e.code );
                }
            }
          }
        }
        ------------------------------------------------------------

              joehw Joe Wang
              hji Huafang Ji (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: