jaxb
  1. jaxb
  2. JAXB-828

schemagen generates schemas for the xml namespace "http://www.w3.org/XML/1998/namespace"

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.1.11, 2.1.12, 2.1.13, 2.2, 2.2.1, 2.2.2, 2.2.3, 2.2.3u1
    • Fix Version/s: None
    • Component/s: schemagen
    • Labels:
      None

      Description

      If I have defined classes which use elements from the standard XML namespace "http://www.w3.org/XML/1998/namespace", and then run those through schemagen, schemagen will create a separate xsd for that namespace, and also include bindings for that namespace in the episode file, if I choose to generate one of those.

      The problem is that this namespace is treated special in XML (including by xjc), but not by schemagen. For example, the resultant episode file is invalid because it contains a prefix mapping such as this:
      xmlns:tns="http://www.w3.org/XML/1998/namespace"

      That's illegal (you can't bind that namespace to any prefix other than 'xml'), and in fact, xjc knows this; xjc will reject the episode file if I try to include it in an invocation.

      Furthermore, the generated schema for my own namespace now has an <xs:import> with a schemaLocation of the generated xml schema, rather than the well-defined schema location.

      Since there is a well-defined schema already for this namespace (at http://www.w3.org/2001/xml.xsd), there is no reason for schemagen to generate one when it's generating a schema from source code. Instead, I think it should generate something like this:

      <xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/xml.xsd"/>

      ...and then not generate another xsd for the items in the code.

      The comments at http://www.java.net/node/645497 (5 years old) appear to agree with me.

      A more generic approach would be to allow me to tell schemagen not generate xsds for certain namespaces of my choice, and instead to just insert an <xs:import> either with no schemaLocation, or with a schemaLocation of my choice (no schemaLocation would work for consumers who are using an XMLCatalog to find the appropriate schemas).

      1. package-info.java
        0.2 kB
        matunos
      2. SampleElement.java
        0.7 kB
        matunos
      3. schema1.xsd
        0.4 kB
        matunos
      4. schema2.xsd
        0.2 kB
        matunos
      5. sun-jaxb.episode
        0.5 kB
        matunos

        Activity

        Hide
        matunos added a comment -

        I've attached 5 files. The 2 java files are for a java package named 'schemagenSample'. The two xsds and the episode file are the results of running the following command:

        $ schemagen.sh -cp . -episode sun-jaxb.episode schemagenSample/*

        Show
        matunos added a comment - I've attached 5 files. The 2 java files are for a java package named 'schemagenSample'. The two xsds and the episode file are the results of running the following command: $ schemagen.sh -cp . -episode sun-jaxb.episode schemagenSample/*
        Hide
        Martin Grebac added a comment -

        Changing to enhancement, not really an issue.

        Show
        Martin Grebac added a comment - Changing to enhancement, not really an issue.
        Hide
        jinahya added a comment -

        I've never use `xml:xxx` attributes so far. And I just got this issue with Java 1.8.0.
        What if anyone is intending to use those generated (two xsd documents) directly on HTTP output?

        Show
        jinahya added a comment - I've never use `xml:xxx` attributes so far. And I just got this issue with Java 1.8.0. What if anyone is intending to use those generated (two xsd documents) directly on HTTP output?

          People

          • Assignee:
            Martin Grebac
            Reporter:
            matunos
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: