Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request for clarification on XSD mappings #59

Closed
sparkyfen opened this issue Feb 19, 2015 · 13 comments
Closed

Request for clarification on XSD mappings #59

sparkyfen opened this issue Feb 19, 2015 · 13 comments
Assignees
Labels
Milestone

Comments

@sparkyfen
Copy link

Hello there,

I've got a use case in which I would like to use XSD files that Amazon provides external facing developers and turn them into JSON objects which I can populate with data.
Some example XSD files include: amzn-base.xsd and product.xsd.

I've used JaxB to take the XSD files and turn them into Java objects which I can set the values in. However, utilizing NodeJS for a current project, I'm looking to do a similar thing with a different library (this one). Could someone help me clarify if this project can be used to pass a XSD file to it and have it give me either JSON or JSON schema to which I can fill in/generate values and then convert to the XML needed?

Thanks!

@highsource
Copy link
Owner

Hi,

yes, this absolutely looks like a use case for Jsonix. Jsonix is basically pretty much like JAXB for JavaScript. Runs on Node.js (as well as in browsers).

What Jsonix does:

  • First you'll generate mappings for your XML Schemas. This is very much like using XJC in JAXB, you give your schemas in and get mappings which describe XML<->JSON conversion. This is normally the hardest step but since you've already used JAXb for your schemas, this won't be a big problem.
  • In the runtime you'll create a Jsonix context (var context = new Jsonix.Context([Base, Product]);) and the use it to create unmarshallers or marshallers to convert between XML and JSON. Pretty much like JAXBContext/marshaller/unmarshaller in JAXB.
  • Thus you can build your payload JSON and marshall it in XML form (which will conform to your schemas) or unmarshal XML into JSON in the known format.
  • And you'll be ablo to do all of this in Node.js. Runtime is pure JavaScript, schema compilation uses a shipped Java library.

What Jsonix does not do:

  • It does not generate JSON Schema (yet).
  • It does not generate JSON "blueprints" for you to fill in. You can take some blueprint XML, unmarshal it, JSON.stringify to the console and use that as JSON blueprint, this is what people usually do.

To get you started, here's a basic but complete "purchase order" example:

Using Jsonix Schema Compiler:

I can help you to compile your first schemas and to get the basic things run, this is normally no big deal.

Best wishes,
Alexey

@highsource highsource self-assigned this Feb 19, 2015
@highsource highsource added this to the 2.1.2 milestone Feb 19, 2015
@sparkyfen
Copy link
Author

Hey Alexey,

Thanks for taking the time to give me this detailed description! I do NOT have any XML yet for the above XSD files and I'm looking for a way to get some generated some how. You mentioned that I would need blueprint XML to start with and I just don't have a working example of any for these files.

I've been able to compile mappings for Books.xsd without an issue. However, when trying to compile Product.xsd I was getting null pointers. I figured it was because it was missing the extra XSD files required. I added them all in and now I'm getting errors that the schema cannot contain two global components. I remember coming across this issue in the past with my Java application and it required you to make a bindings.xjb file to decide which ones should be named what. Do you have an example of the bindings.xjb in which you fix the "multiple occurences" of a variable?

Thanks!

Edit: Exact error is:

$ java -jar node_modules/jsonix-schema-compiler/lib/jsonix-schema-compiler-full.jar -compact -logLevel TRACE -d mappings -p Product Product.xsd

[ERROR] sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of ',SuperLongString'.
  line 1904 of file:/path/to/amzn-base.xsd

[ERROR] sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of ',NoiseLevelDimension'.
  line 2776 of file:/path/to/amzn-base.xsd

[ERROR] sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of ',EnergyConsumptionUnitOfMeasure'.
  line 3144 of file:/path/to/amzn-base.xsd

[ERROR] sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of ',NoiseLevelUnitOfMeasure'.
  line 3188 of file:/path/to/amzn-base.xsd

[ERROR] sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of ',EnergyConsumptionDimension'.
  line 3852 of file:/path/to/amzn-base.xsd

[ERROR] sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of ',BluRayRegionType'.
  line 130 of file:/path/to/Video.xsd

[ERROR] sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of ',VideotapeRecordingSpeedType'.
  line 217 of file:/path/to/Video.xsd

[ERROR] sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of ',VinylRecordDetailsType'.
  line 110 of file:/path/to/Music.xsd

[ERROR] sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of ',Recall'.
  line 203 of file:/path/to/ToysBaby.xsd

[ERROR] sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of ',AgeRecommendation'.
  line 222 of file:/path/to/ToysBaby.xsd

[ERROR] sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of ',WeightRecommendation'.
  line 237 of file:/path/to/ToysBaby.xsd

[ERROR] sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of ',HeightRecommendation'.
  line 250 of file:/path/to/ToysBaby.xsd

[ERROR] sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of ',DockingStationExternalInterfaceTypeValues'.
  line 1610 of file:/path/to/Computers.xsd

[ERROR] sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of ',GraphicsRAMTypeValues'.
  line 1864 of file:/path/to/Computers.xsd

[ERROR] sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of ',HardDriveInterfaceTypeValues'.
  line 1921 of file:/path/to/Computers.xsd

[ERROR] sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of ',ModemTypeValues'.
  line 2105 of file:/path/to/Computers.xsd

[ERROR] sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of ',ProcessorTypeValues'.
  line 2141 of file:/path/to/Computers.xsd

[ERROR] sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of ',WirelessTypeValues'.
  line 2286 of file:/path/to/Computers.xsd

[ERROR] sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of ',ResolutionUnitOfMeasure'.
  line 2529 of file:/path/to/Computers.xsd

[ERROR] sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of ',ApertureDimension'.
  line 2348 of file:/path/to/CameraPhoto.xsd

[ERROR] sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of ',ContinuousShootingDimension'.
  line 2355 of file:/path/to/CameraPhoto.xsd

[ERROR] sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of ',PowerDimension'.
  line 2376 of file:/path/to/CameraPhoto.xsd

[ERROR] sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of ',ApertureUnitOfMeasure'.
  line 2383 of file:/path/to/CameraPhoto.xsd

[ERROR] sch-props-correct.2: A schema cannot contain two global components with the same name; this schema contains two occurrences of ',ContinuousShootingUnitOfMeasure'.
  line 2388 of file:/path/to/CameraPhoto.xsd

Exception in thread "main" java.lang.NullPointerException: The validated object is null
        at org.apache.commons.lang3.Validate.notNull(Validate.java:222)
        at org.apache.commons.lang3.Validate.notNull(Validate.java:203)
        at org.hisrc.jsonix.configuration.ModulesConfigurationUnmarshaller.unmarshal(ModulesConfigurationUnmarshaller.java:119)
        at org.hisrc.jsonix.execution.JsonixInvoker.execute(JsonixInvoker.java:34)
        at org.hisrc.jsonix.JsonixMain.execute(JsonixMain.java:107)
        at org.hisrc.jsonix.JsonixMain.main(JsonixMain.java:76)

The files in question:

@sparkyfen
Copy link
Author

I believe I need something similar to this for each conflict but I'm not sure exactly what the syntax is to get it working.

Command:

$ java -jar node_modules/jsonix-schema-compiler/lib/jsonix-schema-compiler-full.jar -compact -logLevel TRACE -d mappings -p Product Product.xsd -b bindings.xjb
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings
  version="2.1"
  xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
  xmlns:jsonix="http://jsonix.highsource.org/customizations"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"

  jaxb:extensionBindingPrefixes="xjc jsonix">

  <jaxb:bindings schemaLocation="amzn-base.xsd" node="/xs:schema">
    <jaxb:schemaBindings>
      <jxb:bindings node="//xs:simpleType[@name='SuperLongString']">
        <property name="AmznBaseSuperLongString" />
      </jxb:bindings>
      <jxb:bindings node="//xs:complexType[@name='NoiseLevelDimension']">
        <property name="AmznBaseNoiseLevelDimension" />
      </jxb:bindings>
      <jxb:bindings node="//xs:simpleType[@name='EnergyConsumptionUnitOfMeasure']">
        <property name="AmznBaseEnergyConsumptionUnitOfMeasure" />
      </jxb:bindings>
      <jxb:bindings node="//xs:simpleType[@name='EnergyConsumptionUnitOfMeasure']">
        <property name="AmznBaseEnergyConsumptionUnitOfMeasure" />
      </jxb:bindings>
      <jxb:bindings node="//xs:simpleType[@name='NoiseLevelUnitOfMeasure']">
        <property name="AmznBaseNoiseLevelUnitOfMeasure" />
      </jxb:bindings>
      <jxb:bindings node="//xs:complexType[@name='EnergyConsumptionDimension']">
        <property name="AmznBaseEnergyConsumptionDimension" />
      </jxb:bindings>
    </jaxb:schemaBindings>
  </jaxb:bindings>

  <jaxb:bindings schemaLocation="Video.xsd" node="/xs:schema">
    <jaxb:schemaBindings>
      <jxb:bindings node="//xs:simpleType[@name='BluRayRegionType']">
        <property name="VideoBluRayRegionType" />
      </jxb:bindings>
      <jxb:bindings node="//xs:simpleType[@name='VideotapeRecordingSpeedType']">
        <property name="VideoVideotapeRecordingSpeedType" />
      </jxb:bindings>
    </jaxb:schemaBindings>
  </jaxb:bindings>

  <jaxb:bindings schemaLocation="Music.xsd" node="/xs:schema">
    <jaxb:schemaBindings>
      <jxb:bindings node="//xs:simpleType[@name='VinylRecordDetailsType']">
        <property name="MusicVinylRecordDetailsType" />
      </jxb:bindings>
    </jaxb:schemaBindings>
  </jaxb:bindings>

  <jaxb:bindings schemaLocation="ToysBaby.xsd" node="/xs:schema">
    <jaxb:schemaBindings>
      <jxb:bindings node="//xs:element[@name='Recall']">
        <property name="ToysBabyRecall" />
      </jxb:bindings>
      <jxb:bindings node="//xs:element[@name='AgeRecommendation']">
        <property name="ToysBabyAgeRecommendation" />
      </jxb:bindings>
      <jxb:bindings node="//xs:element[@name='WeightRecommendation']">
        <property name="ToysBabyWeightRecommendation" />
      </jxb:bindings>
      <jxb:bindings node="//xs:element[@name='HeightRecommendation']">
        <property name="ToysBabyHeightRecommendation" />
      </jxb:bindings>
    </jaxb:schemaBindings>
  </jaxb:bindings>

  <jaxb:bindings schemaLocation="Computers.xsd" node="/xs:schema">
    <jaxb:schemaBindings>
      <jxb:bindings node="//xs:simpleType[@name='DockingStationExternalInterfaceTypeValues']">
        <property name="ComputersDockingStationExternalInterfaceTypeValues" />
      </jxb:bindings>
      <jxb:bindings node="//xs:simpleType[@name='GraphicsRAMTypeValues']">
        <property name="ComputersGraphicsRAMTypeValues" />
      </jxb:bindings>
      <jxb:bindings node="//xs:simpleType[@name='HardDriveInterfaceTypeValues']">
        <property name="ComputersHardDriveInterfaceTypeValues" />
      </jxb:bindings>
      <jxb:bindings node="//xs:simpleType[@name='ModemTypeValues']">
        <property name="ComputersModemTypeValues" />
      </jxb:bindings>
      <jxb:bindings node="//xs:simpleType[@name='ProcessorTypeValues']">
        <property name="ComputersProcessorTypeValues" />
      </jxb:bindings>
      <jxb:bindings node="//xs:simpleType[@name='WirelessTypeValues']">
        <property name="ComputersWirelessTypeValues" />
      </jxb:bindings>
      <jxb:bindings node="//xs:simpleType[@name='ResolutionUnitOfMeasure']">
        <property name="ComputersResolutionUnitOfMeasure" />
      </jxb:bindings>
    </jaxb:schemaBindings>
  </jaxb:bindings>

  <jaxb:bindings schemaLocation="CameraPhoto.xsd" node="/xs:schema">
    <jaxb:schemaBindings>
      <jxb:bindings node="//xs:complexType[@name='ApertureDimension']">
        <property name="CameraPhotoApertureDimension" />
      </jxb:bindings>
      <jxb:bindings node="//xs:complexType[@name='ContinuousShootingDimension']">
        <property name="CameraPhotoContinuousShootingDimension" />
      </jxb:bindings>
      <jxb:bindings node="//xs:complexType[@name='PowerDimension']">
        <property name="CameraPhotoPowerDimension" />
      </jxb:bindings>
      <jxb:bindings node="//xs:simpleType[@name='ApertureUnitOfMeasure']">
        <property name="CameraPhotoApertureUnitOfMeasure" />
      </jxb:bindings>
      <jxb:bindings node="//xs:simpleType[@name='ContinuousShootingUnitOfMeasure']">
        <property name="CameraPhotoContinuousShootingUnitOfMeasure" />
      </jxb:bindings>
    </jaxb:schemaBindings>
  </jaxb:bindings>

</jaxb:bindings>

@sparkyfen
Copy link
Author

java -jar ./node_modules/jsonix-schema-compiler/lib/jsonix-schema-compiler-full.jar -compact -logLevel TRACE -d mappings amzn-base.xsd Video.xsd Music.xsd Computers.xsd CameraPhoto.xsd ToysBaby.xsd -b bindings.xjb

I've updated the file and I'm getting the following errors now:

[ERROR] 'BluRayRegionType' is already defined
  line 137 of file:/path/to/Video.xsd

[ERROR] (related to above error) the first definition appears here
  line 4233 of file:/path/to/amzn-base.xsd

[ERROR] 'VideotapeRecordingSpeedType' is already defined
  line 226 of file:/path/to/Video.xsd

[ERROR] (related to above error) the first definition appears here
  line 911 of file:/path/to/amzn-base.xsd

[ERROR] 'VinylRecordDetailsType' is already defined
  line 121 of file:/path/to/Music.xsd

[ERROR] (related to above error) the first definition appears here
  line 4241 of file:/path/to/amzn-base.xsd

[ERROR] 'Recall' is already defined
  line 216 of file:/path/to/ToysBaby.xsd

[ERROR] (related to above error) the first definition appears here
  line 4033 of file:/path/to/amzn-base.xsd

[ERROR] 'AgeRecommendation' is already defined
  line 231 of file:/path/to/ToysBaby.xsd

[ERROR] (related to above error) the first definition appears here
  line 4052 of file:/path/to/amzn-base.xsd

[ERROR] 'WeightRecommendation' is already defined
  line 244 of file:/path/to/ToysBaby.xsd

[ERROR] (related to above error) the first definition appears here
  line 4067 of file:/path/to/amzn-base.xsd

[ERROR] 'HeightRecommendation' is already defined
  line 257 of file:/path/to/ToysBaby.xsd

[ERROR] (related to above error) the first definition appears here
  line 4080 of file:/path/to/amzn-base.xsd

[ERROR] 'DockingStationExternalInterfaceTypeValues' is already defined
  line 1623 of file:/path/to/Computers.xsd

[ERROR] (related to above error) the first definition appears here
  line 454 of file:/path/to/amzn-base.xsd

[ERROR] 'GraphicsRAMTypeValues' is already defined
  line 1921 of file:/path/to/Computers.xsd

[ERROR] (related to above error) the first definition appears here
  line 616 of file:/path/to/amzn-base.xsd

[ERROR] 'HardDriveInterfaceTypeValues' is already defined
  line 1978 of file:/path/to/Computers.xsd

[ERROR] (related to above error) the first definition appears here
  line 675 of file:/path/to/amzn-base.xsd

[ERROR] 'ModemTypeValues' is already defined
  line 2111 of file:/path/to/Computers.xsd

[ERROR] (related to above error) the first definition appears here
  line 435 of file:/path/to/amzn-base.xsd

[ERROR] 'ProcessorTypeValues' is already defined
  line 2207 of file:/path/to/Computers.xsd

[ERROR] (related to above error) the first definition appears here
  line 955 of file:/path/to/amzn-base.xsd

[ERROR] 'WirelessTypeValues' is already defined
  line 2313 of file:/path/to/Computers.xsd

[ERROR] (related to above error) the first definition appears here
  line 933 of file:/path/to/amzn-base.xsd

[ERROR] 'ResolutionUnitOfMeasure' is already defined
  line 2534 of file:/path/to/Computers.xsd

[ERROR] (related to above error) the first definition appears here
  line 3127 of file:/path/to/amzn-base.xsd

[ERROR] 'ApertureDimension' is already defined
  line 2355 of file:/path/to/CameraPhoto.xsd

[ERROR] (related to above error) the first definition appears here
  line 3838 of file:/path/to/amzn-base.xsd

[ERROR] 'ContinuousShootingDimension' is already defined
  line 2362 of file:/path/to/CameraPhoto.xsd

[ERROR] (related to above error) the first definition appears here
  line 3845 of file:/path/to/amzn-base.xsd

[ERROR] 'PowerDimension' is already defined
  line 2383 of file:/path/to/CameraPhoto.xsd

[ERROR] (related to above error) the first definition appears here
  line 3817 of file:/path/to/amzn-base.xsd

[ERROR] 'ApertureUnitOfMeasure' is already defined
  line 2388 of file:/path/to/CameraPhoto.xsd

[ERROR] (related to above error) the first definition appears here
  line 3134 of file:/path/to/amzn-base.xsd

[ERROR] 'ContinuousShootingUnitOfMeasure' is already defined
  line 2393 of file:/path/to/CameraPhoto.xsd

[ERROR] (related to above error) the first definition appears here
  line 3139 of file:/path/to/amzn-base.xsd

Exception in thread "main" java.lang.NullPointerException: The validated object is null
        at org.apache.commons.lang3.Validate.notNull(Validate.java:222)
        at org.apache.commons.lang3.Validate.notNull(Validate.java:203)
        at org.hisrc.jsonix.configuration.ModulesConfigurationUnmarshaller.unmarshal(ModulesConfigurationUnmarshaller.java:119)
        at org.hisrc.jsonix.execution.JsonixInvoker.execute(JsonixInvoker.java:34)
        at org.hisrc.jsonix.JsonixMain.execute(JsonixMain.java:107)
        at org.hisrc.jsonix.JsonixMain.main(JsonixMain.java:76)
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
  xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
  xmlns:jsonix="http://jsonix.highsource.org/customizations"
  xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
  jaxb:version="2.1"
  jaxb:extensionBindingPrefixes="jsonix">

  <jaxb:bindings>
    <jaxb:globalBindings typesafeEnumMaxMembers="700" />
  </jaxb:bindings>

  <jaxb:bindings schemaLocation="amzn-base.xsd" node="/xs:schema">
    <jaxb:schemaBindings>

      <jaxb:package name="com.amazon.po.amznbase" />

      <jaxb:nameXmlTransform>
        <jaxb:elementName prefix="Amzn-Base" />
      </jaxb:nameXmlTransform>

    </jaxb:schemaBindings>

    <jaxb:bindings node="//xs:simpleType[@name='SuperLongString']">
      <jaxb:class name="AmznBaseSuperLongString" />
      <jaxb:property name="AmznBaseSuperLongString" />
    </jaxb:bindings>
    <jaxb:bindings node="//xs:complexType[@name='NoiseLevelDimension']">
      <jaxb:class name="AmznBaseNoiseLevelDimension" />
      <jaxb:property name="AmznBaseNoiseLevelDimension" />
    </jaxb:bindings>
    <jaxb:bindings node="//xs:simpleType[@name='EnergyConsumptionUnitOfMeasure']">
      <jaxb:class name="AmznBaseEnergyConsumptionUnitOfMeasure" />
      <jaxb:property name="AmznBaseEnergyConsumptionUnitOfMeasure" />
    </jaxb:bindings>
    <jaxb:bindings node="//xs:simpleType[@name='EnergyConsumptionUnitOfMeasure']">
      <jaxb:class name="AmznBaseEnergyConsumptionUnitOfMeasure" />
      <jaxb:property name="AmznBaseEnergyConsumptionUnitOfMeasure" />
    </jaxb:bindings>
    <jaxb:bindings node="//xs:simpleType[@name='NoiseLevelUnitOfMeasure']">
      <jaxb:class name="AmznBaseNoiseLevelUnitOfMeasure" />
      <jaxb:property name="AmznBaseNoiseLevelUnitOfMeasure" />
    </jaxb:bindings>
    <jaxb:bindings node="//xs:complexType[@name='EnergyConsumptionDimension']">
      <jaxb:class name="AmznBaseEnergyConsumptionDimension" />
      <jaxb:property name="AmznBaseEnergyConsumptionDimension" />
    </jaxb:bindings>

    <jsonix:packageMapping
            packageName="com.amazon.po.amznbase"
            spaceName="AMZNBASE" />

  </jaxb:bindings>

  <jaxb:bindings schemaLocation="Video.xsd" node="/xs:schema">
    <jaxb:schemaBindings>

      <jaxb:package name="com.amazon.po.video" />

      <jaxb:nameXmlTransform>
        <jaxb:elementName prefix="Video" />
      </jaxb:nameXmlTransform>

    </jaxb:schemaBindings>

    <jaxb:bindings node="//xs:simpleType[@name='BluRayRegionType']">
      <jaxb:class name="VideoBluRayRegionType" />
      <jaxb:property name="VideoBluRayRegionType" />
    </jaxb:bindings>
    <jaxb:bindings node="//xs:simpleType[@name='VideotapeRecordingSpeedType']">
      <jaxb:class name="VideoVideotapeRecordingSpeedType" />
      <jaxb:property name="VideoVideotapeRecordingSpeedType" />
    </jaxb:bindings>

    <jsonix:packageMapping
            packageName="com.amazon.po.video"
            spaceName="VIDEO" />

  </jaxb:bindings>

  <jaxb:bindings schemaLocation="Music.xsd" node="/xs:schema">

    <jaxb:schemaBindings>

      <jaxb:package name="com.amazon.po.music" />

      <jaxb:nameXmlTransform>
        <jaxb:elementName prefix="Music" />
      </jaxb:nameXmlTransform>

    </jaxb:schemaBindings>

    <jaxb:bindings node="//xs:simpleType[@name='VinylRecordDetailsType']">
      <jaxb:class name="MusicVinylRecordDetailsType" />
      <jaxb:property name="MusicVinylRecordDetailsType" />
    </jaxb:bindings>

    <jsonix:packageMapping
            packageName="com.amazon.po.music"
            spaceName="MUSIC" />

  </jaxb:bindings>

  <jaxb:bindings schemaLocation="ToysBaby.xsd" node="/xs:schema">

    <jaxb:schemaBindings>

      <jaxb:package name="com.amazon.po.toysbaby" />

      <jaxb:nameXmlTransform>
        <jaxb:elementName prefix="ToysBaby" />
      </jaxb:nameXmlTransform>

    </jaxb:schemaBindings>

    <jaxb:bindings node="//xs:element[@name='Recall']">
      <jaxb:class name="ToysBabyRecall" />
      <jaxb:property name="ToysBabyRecall" />
    </jaxb:bindings>
    <jaxb:bindings node="//xs:element[@name='AgeRecommendation']">
      <jaxb:class name="ToysBabyAgeRecommendation" />
      <jaxb:property name="ToysBabyAgeRecommendation" />
    </jaxb:bindings>
    <jaxb:bindings node="//xs:element[@name='WeightRecommendation']">
      <jaxb:class name="ToysBabyWeightRecommendation" />
      <jaxb:property name="ToysBabyWeightRecommendation" />
    </jaxb:bindings>
    <jaxb:bindings node="//xs:element[@name='HeightRecommendation']">
      <jaxb:class name="ToysBabyHeightRecommendation" />
      <jaxb:property name="ToysBabyHeightRecommendation" />
    </jaxb:bindings>

    <jsonix:packageMapping
            packageName="com.amazon.po.toysbaby"
            spaceName="TOYSBABY" />

  </jaxb:bindings>

  <jaxb:bindings schemaLocation="Computers.xsd" node="/xs:schema">
    <jaxb:schemaBindings>

      <jaxb:package name="com.amazon.po.computers" />

      <jaxb:nameXmlTransform>
        <jaxb:elementName prefix="Computers" />
      </jaxb:nameXmlTransform>

    </jaxb:schemaBindings>

    <jaxb:bindings node="//xs:simpleType[@name='DockingStationExternalInterfaceTypeValues']">
      <jaxb:class name="ComputersDockingStationExternalInterfaceTypeValues" />
      <jaxb:property name="ComputersDockingStationExternalInterfaceTypeValues" />
    </jaxb:bindings>
    <jaxb:bindings node="//xs:simpleType[@name='GraphicsRAMTypeValues']">
      <jaxb:class name="ComputersGraphicsRAMTypeValues" />
      <jaxb:property name="ComputersGraphicsRAMTypeValues" />
    </jaxb:bindings>
    <jaxb:bindings node="//xs:simpleType[@name='HardDriveInterfaceTypeValues']">
      <jaxb:class name="ComputersHardDriveInterfaceTypeValues" />
      <jaxb:property name="ComputersHardDriveInterfaceTypeValues" />
    </jaxb:bindings>
    <jaxb:bindings node="//xs:simpleType[@name='ModemTypeValues']">
      <jaxb:class name="ComputersModemTypeValues" />
      <jaxb:property name="ComputersModemTypeValues" />
    </jaxb:bindings>
    <jaxb:bindings node="//xs:simpleType[@name='ProcessorTypeValues']">
      <jaxb:class name="ComputersProcessorTypeValues" />
      <jaxb:property name="ComputersProcessorTypeValues" />
    </jaxb:bindings>
    <jaxb:bindings node="//xs:simpleType[@name='WirelessTypeValues']">
      <jaxb:class name="ComputersWirelessTypeValues" />
      <jaxb:property name="ComputersWirelessTypeValues" />
    </jaxb:bindings>
    <jaxb:bindings node="//xs:simpleType[@name='ResolutionUnitOfMeasure']">
      <jaxb:class name="ComputersResolutionUnitOfMeasure" />
      <jaxb:property name="ComputersResolutionUnitOfMeasure" />
    </jaxb:bindings>

    <jsonix:packageMapping
            packageName="com.amazon.po.computers"
            spaceName="COMPUTERS" />

  </jaxb:bindings>

  <jaxb:bindings schemaLocation="CameraPhoto.xsd" node="/xs:schema">
    <jaxb:schemaBindings>

      <jaxb:package name="com.amazon.po.cameraphoto" />

      <jaxb:nameXmlTransform>
        <jaxb:elementName prefix="CameraPhoto" />
      </jaxb:nameXmlTransform>

    </jaxb:schemaBindings>

    <jaxb:bindings node="//xs:complexType[@name='ApertureDimension']">
      <jaxb:class name="CameraPhotoApertureDimension" />
      <jaxb:property name="CameraPhotoApertureDimension" />
    </jaxb:bindings>
    <jaxb:bindings node="//xs:complexType[@name='ContinuousShootingDimension']">
      <jaxb:class name="CameraPhotoContinuousShootingDimension" />
      <jaxb:property name="CameraPhotoContinuousShootingDimension" />
    </jaxb:bindings>
    <jaxb:bindings node="//xs:complexType[@name='PowerDimension']">
      <jaxb:class name="CameraPhotoPowerDimension" />
      <jaxb:property name="CameraPhotoPowerDimension" />
    </jaxb:bindings>
    <jaxb:bindings node="//xs:simpleType[@name='ApertureUnitOfMeasure']">
      <jaxb:class name="CameraPhotoApertureUnitOfMeasure" />
      <jaxb:property name="CameraPhotoApertureUnitOfMeasure" />
    </jaxb:bindings>
    <jaxb:bindings node="//xs:simpleType[@name='ContinuousShootingUnitOfMeasure']">
      <jaxb:class name="CameraPhotoContinuousShootingUnitOfMeasure" />
      <jaxb:property name="CameraPhotoContinuousShootingUnitOfMeasure" />
    </jaxb:bindings>

    <jsonix:packageMapping
            packageName="com.amazon.po.cameraphoto"
            spaceName="CAMERAPHOTO" />

  </jaxb:bindings>

</jaxb:bindings>

@highsource
Copy link
Owner

Hi,

yes you'll probably need to customize, I'll help you compile the schemas. This is the hardest part.

I was thinking to move this to the support project where we could work on these schemas:

But then I saw this in these schemas:

AMAZON.COM CONFIDENTIAL. This document and the information contained in it are
confidential and proprietary information of Amazon.com and may not be reproduced,
distributed or used, in whole or in part, for any purpose other than as necessary
to list products for sale on the www.amazon.com web site pursuant to an agreement
with Amazon.com.

This is a bit worrying, I wouldn't like any legal problems.
I'm not quite sure how to proceed at the moment. I'll try to compile your schemas later on but under circumstances I can't collaborate in public repos.

Best wishes,
Alexey

@highsource
Copy link
Owner

After a brief look at the schemas they seem to be invalid. They define global elements an types which were already defined in amzn-base.xsd. Example:

CameraPhoto.xsd:

    <xsd:complexType name="PowerDimension">
        <xsd:simpleContent>
            <xsd:extension base="xsd:positiveInteger">
                <xsd:attribute name="unitOfMeasure" type="CameraPowerUnitOfMeasure" use="required"/>
            </xsd:extension>
        </xsd:simpleContent>
    </xsd:complexType>

amzn-base.xsd:

    <xsd:complexType name="PowerDimension">
        <xsd:simpleContent>
            <xsd:extension base="Dimension">
                <xsd:attribute name="unitOfMeasure" type="PowerUnitOfMeasure" use="required"/>
            </xsd:extension>
        </xsd:simpleContent>
    </xsd:complexType>

And that's in the same (empty) namespace. This is invalid from XML Schema PoV. I'll think about how it might be solved.

@sparkyfen
Copy link
Author

@highsource Thanks for taking a look. As far as the disclaimer, these XSD files are in the public domain, external facing. You can find the files in a Github repo already as well as Google (It's the 5th one down).

If you would like to take this request to jsonix-support, I'm completely fine with it.

As far as the empty namespace goes, I can't edit the XSD files incase they change the schema in the future. Is there something I can do to help try to get them working?

@highsource
Copy link
Owner

Ok, I'm fine with that. The worst case scenario is a DMCA takedown on jsonix-support but it's not big deal.

I think we can just strip amzn-base.xsd down to whatever other schemas need. Give me a few hours, I'll get something working. And if you could find some XML examples for these schemas, that would be very helpful.

@sparkyfen
Copy link
Author

@highsource I agree it would be helpful :) This is one of the issue I'm having. There are not a lot of example XML documents that conform to the schema.

I've got one or two but they are pretty small and don't encompass all the attributes.

None the less...

Note: All feeds eventually get wrapped into an amazon-envelope which the XSD is here. The rest of the files that amzn-envelope needs to complete are in the same directory. I setup a simple wget script to get them all.
Eventually your directory structure will probably match the Github repo I posted above.

wget https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/amzn-base.xsd
wget https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/amzn-header.xsd
wget https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/CatPIL.xsd
wget https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/Customer.xsd
wget https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/FulfillmentCenter.xsd
wget https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/FulfillmentOrderCancellationRequest.xsd
wget https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/FulfillmentOrderRequest.xsd
wget https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/Image.xsd
wget https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/Inventory.xsd
wget https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/Item.xsd
wget https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/Listings.xsd
wget https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/Loyalty.xsd
wget https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/MultiChannelOrderReport.xsd
wget https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/NavigationReport.xsd
wget https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/Offer.xsd
wget https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/OrderAcknowledgement.xsd
wget https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/OrderAdjustment.xsd
wget https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/OrderFulfillment.xsd
wget https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/OrderNotificationReport.xsd
wget https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/OrderReport.xsd
wget https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/Override.xsd
wget https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/Price.xsd
wget https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/ProcessingReport.xsd
wget https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/Product.xsd
wget https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/ProductImage.xsd
wget https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/Relationship.xsd
wget https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/ReverseFeed.xsd
wget https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/SettlementReport.xsd
wget https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/Store.xsd
wget https://images-na.ssl-images-amazon.com/images/G/01/rainier/help/xsd/release_4_1/WebstoreItem.xsd

With these files being found, we not only have to compile Product.xsd and amzn-base.xsd, it seems we need to get amzn-envelope.xsd compiling with its "children" as well.

@highsource
Copy link
Owner

Ok, I've managed to compile your schemas:

As I said, some of the schemas are invalid. Some types are defined in amzn-base.xsd as well as other schemas. I had to fix it and then it compiled without much problems.

Unfortunately "fixing" means patching a few XSD files. There are three ways to fix duplicate types:

  • Remove the duplicate type from amzn-base.xsd.
  • Remove the duplicate type from the specific schema.
  • Rename the duplicate type in the specific schema.

At the moment I've removed duplicate types from amzn-base.xsd in all the occasions where these types were only used in one specific schema. I think there was exactly one case when a type in question was used in several schemas. In this case I've renamed it in on of the specific schemas.

As I see it, there is no way around this, schemas must be valid, otheriwise generation does not work, period. No customization would help. Fortunately the fix is rather trivial (removing duplicate types). I think a long-term solution should be a "patch" XSLT which would be applied to schemas. This would make it a bit easier to update schema versions. But as it stands now, it is also not a big deal to remove these types manually.

Now, I've also added a package.json for Node.js and a "roundtrip" nodeunit test. The tests unmarshalls/marshalls/unmarshalls an XML and checks if the data is still the same. This more or less ensures if unmarshalling/marshalling works. So far both XML files you've provided seem to work. This is the JSON you get:

{
    "name": {
        "namespaceURI": "",
        "localPart": "AmazonEnvelope",
        "prefix": "",
        "key": "AmazonEnvelope",
        "string": "AmazonEnvelope"
    },
    "value": {
        "TYPE_NAME": "AMZN.AmazonEnvelope",
        "header": {
            "TYPE_NAME": "AMZN.Header",
            "documentVersion": "1.01",
            "merchantIdentifier": "M_EXAMPLE_123456"
        },
        "messageType": "Product",
        "purgeAndReplace": false,
        "message": [
            {
                "TYPE_NAME": "AMZN.AmazonEnvelope.Message",
                "messageID": 1,
                "operationType": "Update",
                "product": {
                    "TYPE_NAME": "AMZN.Product",
                    "sku": "56789",
                    "standardProductID": {
                        "TYPE_NAME": "AMZN.StandardProductID",
                        "type": "ASIN",
                        "value": "B0EXAMPLEG"
                    },
                    "productTaxCode": "A_GEN_NOTAX",
                    "descriptionData": {
                        "TYPE_NAME": "AMZN.Product.DescriptionData",
                        "title": "Example Product Title",
                        "brand": "Example Product Brand",
                        "description": "This is an example product description.",
                        "bulletPoint": [
                            "Example Bullet Point 1",
                            "Example Bullet Point 2"
                        ],
                        "msrp": {
                            "TYPE_NAME": "AMZN.CurrencyAmount",
                            "currency": "USD",
                            "value": 25.19
                        },
                        "manufacturer": "Example Product Manufacturer",
                        "itemType": "example-item-type"
                    },
                    "productData": {
                        "TYPE_NAME": "AMZN.Product.ProductData",
                        "health": {
                            "TYPE_NAME": "AMZN.Health",
                            "productType": {
                                "TYPE_NAME": "AMZN.Health.ProductType",
                                "healthMisc": {
                                    "TYPE_NAME": "AMZN.HealthMisc",
                                    "ingredients": [
                                        "Example Ingredients"
                                    ],
                                    "directions": "Example Directions"
                                }
                            }
                        }
                    }
                }
            }
        ]
    }
}

You can ignore prefix/key/string and TYPE NAME, you normally don't need them for marshalling.

So it looks like it works more or less well now. Please let me know if it works for you.

@highsource
Copy link
Owner

@brutalhonesty Did you have a chance to take a look at this? I'm wrapping up the release and am inclined to close the issue.

@sparkyfen
Copy link
Author

@highsource Sorry for the delay! I just met with my team to discuss this and it looks like it the XSD files appear to be invalid. We've removed extra elements and followed the same method you used to resolve this issue. Thanks for all your help!

@highsource
Copy link
Owner

@brutalhonesty Super, thanks for letting me know. Feel free to drop a note if you need further support with Jsonix or your schemas.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants