Fix namespace resolution when elementFormDefault is 'unqualified' or unset on xs:schema #280
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change fixes the way that XML namespaces are determined for non-top-level elements & attributes within an XSD schema, resulting in more correct generated code in cases where the schema element lacks the
elementFormDe257, fault/attributeFormDefaultattributes, or has them set to the default value ofunqualified.There are multiple open issues (at least #257, #243, and #232) that I think all trace back to this area of the code and would be helped (if not entirely solved) by this change.
Background
An XSD schema may contain multiple element and attribute definitions. These definitions may be either top-level (direct children of the
<schema>element itself) or local (more deeply nested, for example under a<complexType>element).In the case of top-level element and attribute definitions, the XML namespace assigned to the element or attribute is always equal to the value of the
targetNamespaceattribute of the containing<schema>element.In the case of local element or attribute definitions, their XML namespaces are determined via a more complex set of rules described in § 3.2.2.2 Mapping Rules for Local Attribute Declarations (attributes) and § 3.3.2.3 Mapping Rules for Local Element Declarations (elements) of the XSD spec. In short: whether local elements & attributes 'inherit' the
targetNamespaceof the containing<schema>is determined by theirtargetNamespaceandformattributes or (in the absence of both), theelementFormDefault/attributeFormDefaultattributes on the containing schema.gowsdlis currently applying the rule for top-level element and attribute definitions to all elements and attributes, regardless of whether they are top-level or not, resulting in incorrect namespaces inxmltags, and thus broken code-generation for some schemas containing local element / attribute definitions.Test coverage
There was actually test coverage of these cases, but the existing test assertions were incorrect.
In particular, the stored expected output for the EPCIS test introduced in #166 encoded a number of incorrect element namespaces. I double-checked the example XML payloads in the standard here to confirm that the existing test was incorrect. See the examples section 9.6 in the EPCIS standard for an example demonstrating that the
<EPCISBody>element, for example, is un-namespaced.