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

TypeInfo.getTypeNamespace() returns unexpected namespace

XMLWordPrintable

    • b46
    • generic
    • generic
    • Verified

      Name: erR10175 Date: 03/10/2004



           If an element is declared using anonymous simple type, TypeInfo.getTypeNamespace()
      returns http://apache.org/xml/xmlschema/1.0/anonymousTypes instead of the schema's
      target namespace.

      The documentation of the interface org.w3c.dom.TypeInfo reads:

      "If the document's schema is an XML Schema [XML Schema Part 1] , the values are computed
      as follows using the post-schema-validation infoset contributions (also called
      PSVI contributions):
      ...
         If the [validity] property exists and is "valid":
         1. ...
         2. ...
         3. ...
         4. If the [type definition anonymous] exists:
             1. ...
             2. Otherwise, expose the namespace and local name of the corresponding anonymous
                type name. "

      This implies that the namespace of the TypeInfo is the *actual value* of
      the targetNamespace attribute of the <schema> ancestor element information item.

      This bug affects new test in JCK 1.5
          api/org_w3c/dom/TypeInfo/index.html#TypeInfo[GetTypeName008]

      The bug is found in jdk1.5.0/beta/b41.

      To reproduce the bug place test.java, test.xsd and test.xml to your current
      directory, then compile and run test.java as shown in the log below:
      ------------------------------------------ test.java
      import org.w3c.dom.Document;
      import org.w3c.dom.TypeInfo;
      import javax.xml.XMLConstants;
      import javax.xml.parsers.DocumentBuilderFactory;

      class test {
           static final String SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
           static final String SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";

           public static void main(String[] args) throws Exception {

               DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
               dbf.setNamespaceAware(true);
               dbf.setValidating(true);
               dbf.setAttribute(SCHEMA_LANGUAGE, XMLConstants.W3C_XML_SCHEMA_NS_URI);
               dbf.setAttribute(SCHEMA_SOURCE, "test.xsd");

               Document document = dbf.newDocumentBuilder().parse("test.xml");

               TypeInfo type = document.getDocumentElement().getSchemaTypeInfo();

               String typeNamespace = type.getTypeNamespace();

               if (!"testNS".equals(typeNamespace)) {
                   System.out.println("returned typeNamespace is " + typeNamespace
                                    + ", but expected testNS");
               } else {
                   System.out.println("OK");
               }
           }
      }
      ----------------------------------------------------

      ------------------------------------------- test.xsd
      <?xml version="1.0"?>
      <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                   xmlns:testNS="testNS"
                   targetNamespace="testNS" elementFormDefault="qualified">
           <xsd:element name="test5">
               <xsd:simpleType>
                   <xsd:restriction base="xsd:string"/>
               </xsd:simpleType>
           </xsd:element>
      </xsd:schema>
      ----------------------------------------------------

      ------------------------------------------- test.xml
      <?xml version='1.0'?>
      <test5 xmlns="testNS">the test</test5>
      ----------------------------------------------------

      ------------------------------------------------ log
      $javac test.java && java -cp . -showversion test
      java version "1.5.0-beta2"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b41)
      Java HotSpot(TM) Client VM (build 1.5.0-beta2-b41, mixed mode)

      returned typeNamespace is http://apache.org/xml/xmlschema/1.0/anonymousTypes, but expected testNS
      ----------------------------------------------------

      ======================================================================

            vkorcl Venugopal K (Inactive)
            reysunw Rey Rey (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: