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

W3CXMLSchemaDescription.getTargetNamespace() returns null instead of NULL_NS_URI

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b32
    • CPU:
      generic
    • OS:
      generic
    • Verification:
      Verified

      Description

      Name: erR10175 Date: 11/11/2003


       
        The method javax.xml.grammar.W3CXMLSchemaDescription.getTargetNamespace()
      returns null if the target namespace attribute is not specified. Expected
      is XMLConstants.NULL_NS_URI.

      The documentation of the field javax.xml.XMLConstants.NULL_NS_URI reads:

      "Namespace URI to use to represent that there is no Namespace.
      Defined by the Namespace specification to be ""."

      This bug affects new test in JCK 1.5 (not yet integrated)
         api/javax_xml/grammar/W3CXMLSchemaDescriptions/index.html#W3CXMLSchemaDescriptions[GetTargetNamespace001]

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

      To reproduce the bug put test.xml, test.xsd and test.java to the work directory,
      then compile and run test.java as shown in the log below:
      ------------------------------ test.xml
      <?xml version="1.0"?>
      <test>
          <description>This is a simple xml document</description>
          <code>no operation</code>
      </test>
      ----------------------------------------

      ------------------------------ test.xsd
      <?xml version="1.0"?>
      <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
          <xsd:element name="test">
              <xsd:complexType>
                  <xsd:sequence>
                      <xsd:element name="description" minOccurs="0"/>
                      <xsd:element name="code"/>
                  </xsd:sequence>
              </xsd:complexType>
          </xsd:element>
      </xsd:schema>
      ----------------------------------------

      ------------------------------ test.java
      import java.io.File;
      import java.util.Collection;
      import java.util.Iterator;
      import javax.xml.XMLConstants;
      import javax.xml.grammar.Grammar;
      import javax.xml.grammar.GrammarCache;
      import javax.xml.grammar.GrammarDescription;
      import javax.xml.grammar.W3CXMLSchemaDescription;
      import javax.xml.parsers.DocumentBuilder;
      import javax.xml.parsers.DocumentBuilderFactory;

      public 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";

          static W3CXMLSchemaDescription getDescription(String xmlFile, String schemaSources) throws RuntimeException {
              DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
              dbf.setNamespaceAware(true);
              dbf.setValidating(true);
              GrammarCache gc = dbf.newGrammarCache();
              dbf.setGrammarCaching(true);
              dbf.setGrammarCache(gc);

              try {
                  dbf.setAttribute(SCHEMA_LANGUAGE, XMLConstants.W3C_XML_SCHEMA_NS_URI);
                  dbf.setAttribute(SCHEMA_SOURCE, schemaSources);
                  DocumentBuilder parser = dbf.newDocumentBuilder();
                  parser.parse(new File(xmlFile));
              } catch (Exception e) {
                  throw new RuntimeException("reading " + xmlFile + " throws " + e);
              }

              Collection grammars = gc.getGrammars(XMLConstants.W3C_XML_SCHEMA_NS_URI);
              for (Iterator it = grammars.iterator(); it.hasNext(); ) {
                  Grammar grammar = (Grammar)(it.next());
                  GrammarDescription descr = grammar.getGrammarDescription();
                  if (descr instanceof W3CXMLSchemaDescription) {
                      return (W3CXMLSchemaDescription)descr;
                  }
              }
              throw new RuntimeException("schema description for " + xmlFile + " is not found");
          }

          public static void main(String [] args) {
              W3CXMLSchemaDescription descr = getDescription("test.xml", "test.xsd");
              System.out.println("descr.getTargetNamespace() returns "
                                + descr.getTargetNamespace());
              System.out.println("XMLConstants.NULL_NS_URI == \'" + XMLConstants.NULL_NS_URI + "\'");
          }
      }
      ----------------------------------------

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

      descr.getTargetNamespace() returns null
      XMLConstants.NULL_NS_URI == ''
      ----------------------------------

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

        Attachments

          Activity

            People

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

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: