In my attempt to use a schema file that I created: ListMatchingProductsResponse.xsd, I run into an error similar to another post but I don't think that the underlying fix is that same.
When I try to parse a sample response:
var ListMatchingProductsResponse = require('/mappings/ListMatchingProductsResponse').ListMatchingProductsResponse;
var Jsonix = require('jsonix').Jsonix;
var context = new Jsonix.Context([ListMatchingProductsResponse]);
var unmarshaller = context.createUnmarshaller();
unmarshaller.unmarshalFile('sample-response.xml',
function (unmarshalled) {
console.log('unmarshalled:', unmarshalled);
});
});
I end up with:
Uncaught Error:
Element [{http://mws.amazonservices.com/schema/Products/2011-10-01}ListMatchingProductsResponse]
could not be unmarshalled as is not known in this context
and the property does not allow DOM content.
I've tried various unintelligent hacks thus far but just don't understand what the problem here is. Hoping that someone with a better eagle-eye view and understanding can help.
What sticks out most clearly for me is that the sample response
ListMatchingProductsResponse
with the http://mws.amazonservices.com/schema/Products/2011-10-01
namespacehttp://localhost:8000/ListMatchingProductsResponse.xsd
namespace because I'm the one creating the schema and defining ListMatchingProductsResponse
as a complexType
.Here's an excerpt from my mappings/ListMatchingProductsResponse.js file which is generated after running: java -jar node_modules/jsonix/lib/jsonix-schema-compiler-full.jar -d mappings -p ListMatchingProductsResponse cache/xsd/localhost_8000/ListMatchingProductsResponse.xsd
{
localName: 'ListMatchingProductsResponse',
typeName: {
namespaceURI: 'http:\/\/localhost:8000\/ListMatchingProductsResponse.xsd',
localPart: 'ListMatchingProductsResponse'
},
I really did not want to change the response because I really have no control over it but I fiddled with it to see if things could be different by fixing the namespace to be my artificial one but that still resulted in the same error ... just that now the namespace being complained about is different:
Uncaught Error:
Element [{http://localhost:8000/ListMatchingProductsResponse.xsd}ListMatchingProductsResponse]
could not be unmarshalled as is not known in this context
and the property does not allow DOM content.
Disclaimer: I'm the author of Jsonix.
I see at least a few problems.
First, I don't see element declarations in your schema. You're trying to unmarshal
ListMatchingProductsResponse
with the http://mws.amazonservices.com/schema/Products/2011-10-01
namespace, but where is it declared in your schema?
Next, your schema has http://localhost:8000/ListMatchingProductsResponse.xsd
as target namespace. Your element has http://mws.amazonservices.com/schema/Products/2011-10-01
namespace. This is suspicious. I'm not saying it's wrong (since there are no global element declarations), but I guess you're mixing schema location and namespace URIs.
So as far as I can tell your schema is not complete and your XML does not match it. I might be wrong (I'd have to analyze all the imports to be sure), but I think you'll need to add global elements and check namespaces.