jaxp
  1. jaxp
  2. JAXP-37

Unrecognized target namespace containing a tilde

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: current
    • Fix Version/s: milestone 1
    • Component/s: www
    • Labels:
      None
    • Environment:

      Operating System: All
      Platform: All

    • Issuezilla Id:
      37

      Description

      JAXP 1.3, included in Sun's Java 5 implementation, cannot load a schema whose
      target namespace contains a tilde character. However, JAXP 1.4 in Java 6 does.
      Here is a small test case.

      Schema file: smalltest.xsd
      <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
      xmlns:tst="http://www.my.test.com/~dummy/test"
      targetNamespace="http://www.my.test.com/~dummy/test"
      elementFormDefault="qualified">
      <xsd:complexType name="SuperTest">
      <xsd:sequence>
      <xsd:element name="test1" type="xsd:string" minOccurs="0"
      maxOccurs="unbounded"/>
      </xsd:sequence>

      <xsd:attribute name="test" type="xsd:int" use="required"/>
      </xsd:complexType>

      <xsd:element name="test" type="tst:SuperTest"/>
      </xsd:schema>

      Test document: smalltest.xml
      <test xmlns="http://www.my.test.com/~dummy/test" test="12">
      <test1>Hello</test1>
      <test1>World</test1>
      </test>

      Test program: TestValid.java
      import java.io.File;
      import java.io.IOException;

      import javax.xml.XMLConstants;
      import javax.xml.transform.stream.StreamSource;
      import javax.xml.validation.Schema;
      import javax.xml.validation.SchemaFactory;
      import javax.xml.validation.Validator;

      import org.xml.sax.SAXException;

      public class TestValid {
      public static void main (String[] args) {
      if (args.length != 2)

      { System.err.println ("Usage: java TestValid <xml file> <schema>"); System.exit (1); }

      String xmlFile = args[0];
      String schemaFile = args[1];

      SchemaFactory sf = SchemaFactory.newInstance
      (XMLConstants.W3C_XML_SCHEMA_NS_URI);
      Schema sm;
      try

      { sm = sf.newSchema (new File (schemaFile)); }

      catch (SAXException se)

      { System.err.println ("Could not read schema"); System.err.println (se.getLocalizedMessage ()); System.exit (1); return; }

      Validator val = sm.newValidator ();
      try

      { val.validate (new StreamSource (xmlFile)); }

      catch (IOException ioe)

      { System.err.println ("Error reading XML file: " + ioe.getLocalizedMessage ()); System.exit (1); return; }

      catch (SAXException se)

      { System.err.println ("Error when validating the document"); System.err.println (se.getLocalizedMessage ()); System.exit (1); return; }

      System.out.println ("The document is valid!");
      }
      }

      Command-line: java TestValid smalltest.xml smalltest.xsd

      With Java 6, I get the The document is valid! message.
      But with Java 5, I get the following error:

      Could not read schema
      src-resolve.4.2: Error resolving component 'tst:SuperTest'. It was detected that
      'tst:SuperTest' is in namespace 'http://www.my.test.com/~dummy/test', but
      components from this namespace are not referenceable from schema document
      'file:///mnt/common/univ/stochas/java/contactcenters/jaxbcc/bin/smalltest.xsd'.
      If this is the incorrect namespace, perhaps the prefix of 'tst:SuperTest' needs
      to be changed. If this is the correct namespace, then an appropriate 'import'
      tag should be added to
      'file:///mnt/common/univ/stochas/java/contactcenters/jaxbcc/bin/smalltest.xsd'.

      So with Java 5, the program does not create the schema object at all.

        Activity

        Hide
        ndw added a comment -

        Can you try replacing all the "~"s with "%7E" and see if it works?

        I wonder if some API is doing that and then the two URIs are different so the
        references don't match.

        Show
        ndw added a comment - Can you try replacing all the "~"s with "%7E" and see if it works? I wonder if some API is doing that and then the two URIs are different so the references don't match.
        Hide
        ericbuist added a comment -

        If I replace the ~ with %7E in the Schema file smalltest.xsd and I run my
        program again, with Java 6 or Java 5, I get

        Error when validating the document
        cvc-elt.1: Cannot find the declaration of element 'test'.

        If I also replace the ~ with %7E in the instance document, I get

        The document is valid!

        But this is only an additional way to remove ~'s.

        Show
        ericbuist added a comment - If I replace the ~ with %7E in the Schema file smalltest.xsd and I run my program again, with Java 6 or Java 5, I get Error when validating the document cvc-elt.1: Cannot find the declaration of element 'test'. If I also replace the ~ with %7E in the instance document, I get The document is valid! But this is only an additional way to remove ~'s.

          People

          • Assignee:
            jaxp-issues
            Reporter:
            ericbuist
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: