question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mappings cannot be generated when using substitutionGroup

See original GitHub issue

What I’m about to report may be

  • a bug
  • or a know limitation
  • or I may just be using the tool incorrectly

Problem

With a schema such as this one which attempts to use substitutionGroup:

<schema
  targetNamespace="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd"
  elementFormDefault="qualified"
  xmlns="http://www.w3.org/2001/XMLSchema"
  xmlns:product="http://mws.amazonservices.com/schema/Products/2011-10-01"
  xmlns:tns="http://mws.amazonservices.com/schema/Products/2011-10-01/default.xsd">

  <import schemaLocation="ProductsAPI_Response.xsd"
          namespace="http://mws.amazonservices.com/schema/Products/2011-10-01" />

  <element name="ItemAttributes" 
           type="tns:ItemAttributesType" 
           substitutionGroup="product:AttributeSet" /> <!-- PROBLEM AT THIS LINE -->

I run into an error stating:

[ERROR] src-resolve: Cannot resolve the name 'product:AttributeSet' to a(n) 'element declaration' component.

Would I be correct in stating that this is a limitation of jsonix-schema-compiler?

Trial & Error

In the example earlier, Jsonix processing fails when the schema file for namespaceA fails to use substitutionGroup to refer to something in namespaceB. So I manipulated the schema to be one namespace and then the command to generate mappings started to work … perhaps that is a hint to help debug this?

<schema
  targetNamespace="http://mws.amazonservices.com/schema/Products/2011-10-01"
  elementFormDefault="qualified"
  xmlns="http://www.w3.org/2001/XMLSchema"
  xmlns:product="http://mws.amazonservices.com/schema/Products/2011-10-01"
  xmlns:tns="http://mws.amazonservices.com/schema/Products/2011-10-01">

  <import schemaLocation="ProductsAPI_Response.xsd"
          namespace="http://mws.amazonservices.com/schema/Products/2011-10-01" />

  <element name="ItemAttributes" 
           type="tns:ItemAttributesType" 
           substitutionGroup="product:AttributeSet" />

The xml traffic I want to parse clearly marks its elements as namespaceA and napespaceB so I can’t parse real traffic with this workaround.

This was just an experiment to get some insight into: Does substitutionGroup work at all when used with jsonix-schema-compiler? And right now I think the answer is that substitutionGroup works within the same namespace but not across.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
highsourcecommented, Sep 16, 2016

Since you’ve solved the issue, PR is not necessary anymore.

1reaction
highsourcecommented, Sep 16, 2016

Substitution groups work fine. See this project, these are pretty complex schemas, use most of the XML Schema featureset including substitution groups.

The problem in your case is probably, well, that AttributeSet could not be found in the right namespace. I can’t say why is this without seeing the schemas. I’d normally do a full text search looking for the declaration of the AttributeSet element, check the namespace, check the ItemAttributesType extends the type of the AttributeSet.

For more support PR your (simplified) test project under https://github.com/highsource/jsonix-support/tree/master/s/someproject (choose your own name for s/someproject).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Substitution Groups
If the substitution group head element is abstract, then an entry will not be added to the generated type for it. This is...
Read more >
Substitution group mappings - IBM
Through substitution groups, XML schemas provide a more powerful model supporting substitution of one named element for another.
Read more >
Problem with substitution group in XML schema - SSDN
XML Discussion Forums,Problem with substitution group in XML schema. ... Generating Java Code for XML (3) ... xml to flat file mapping using......
Read more >
Chapter 37. Element Substitution Red Hat Fuse 7.7
A substitution group is a feature of XML schema that allows you to specify elements that can replace another element in documents generated...
Read more >
Map XML elements to cells in an XML Map - Microsoft Support
Learn about adding and removing XML mapping to an Excel workbook. ... of another element's substitution group through the <substitutionGroup> attribute.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found