Comments (5)
Thanks for catching the issue with minInclusive et al. Just pushed a fix for that.
I've looked at these schema and the first thing that jumps out at me is there's no target namespace. The xsdgen
tool looks for the targetNamespace
attribute on all schema and by default will generate type declarations for all target namespaces. I neglected to handle the case of no name space, detailed here in the spec: https://www.w3.org/TR/xmlschema-0/#UndeclaredTNS .
I tried adding targetNamespace=""
to all the xsd, but hit the following error:
could not dereference {{http://www.w3.org/2001/XMLSchema element} [{{ ref} CatPIL}]}
That was due to a missing CatPIL.xsd. I tried fetching all the xsd and resorted to finding a repo online (https://github.com/anichelabs/amz-mws-xsd). After running against that, I got
complexType _anon353: could not find type "ItemLongStringNotNull" in namespace for element value
I couldn't find where that type was defined.
from go-xml.
@droyo Thank you for trying help.
First of all, I should say, that I found a workaround for task at hand, so don't worry about that.
Just FYI: as a workaround I used xsd2inst
tool from Apach xmlbeans to generate sample xml by xsd and generated Go structs from sample xml with xmljson2struct
tool (github.com/wicast/xj2s). I also tried github.com/gnewton/chidley
, but didn't like it's output - too much redundant code. BTW, this is an example of the code, I hoped to have from the tool (this is an output of xsd2inst
):
type OrderAcknowledgement struct {
MerchantOrderID string `xml:"MerchantOrderID"`
StatusCode string `xml:"StatusCode"`
AmazonOrderItemCode string `xml:"Item>AmazonOrderItemCode"`
MerchantOrderItemID string `xml:"Item>MerchantOrderItemID"`
CancelReason string `xml:"Item>CancelReason"`
AmazonOrderID string `xml:"AmazonOrderID"`
}
This is just to have an idea what I was looking for.
Next, regarding to nemespace issue, it's strange for me, because I was able to run your tool without errors with script and fix I described in the first message. Namely, all xml dependencies could be resolved with amzn-base.xsd
. Only be warned, that Amazon has several versions of schema files, you should have all files from the single source for consistence. If you can use bash
and curl
please use exact command I provided - I found, that without last slash it downloads wrong version. Also, you could try to use this repo: https://raw.githubusercontent.com/highsource/jsonix-support/master/a/amzn/original-schemas/. But I'am sure, that URL and schema names from Amazon I provided earlier should be enough - I used them with other tools without any issues. BTW, there are no reference to "ItemLongStringNotNull" within my copy of schema.
from go-xml.
Thanks for your input.
I went back and followed your exact instructions, and you were right, the schema you provided are sufficient. After applying your fix and a fix to #16, I was able to generate schema by changing
//go:generate xsdgen ../zzz/amzn-base.xsd ../zzz/Price.xsd
to
//go:generate xsdgen -ns "" ../zzz/amzn-base.xsd ../zzz/Price.xsd
Here is what the declaration looks like for the type you provided:
type Anon1 struct {
AmazonOrderID AmazonOrderID `xml:" AmazonOrderID"`
MerchantOrderID string `xml:" MerchantOrderID"`
StatusCode StatusCode `xml:" StatusCode"`
Item []Item `xml:" Item"`
AmazonOrderItemCode AmazonOrderItemCode `xml:" AmazonOrderItemCode"`
MerchantOrderItemID string `xml:" MerchantOrderItemID"`
CancelReason CancelReason `xml:" CancelReason"`
}
// May be one of NoInventory, ShippingAddressUndeliverable, CustomerExchange, BuyerCanceled, GeneralAdjustment, CarrierCreditDecision, RiskAssessmentInformationNotValid, CarrierCoverageFailure, CustomerReturn, MerchandiseNotReceived
type CancelReason string
type Item struct {
AmazonOrderItemCode AmazonOrderItemCode `xml:" AmazonOrderItemCode"`
MerchantOrderItemID string `xml:" MerchantOrderItemID"`
CancelReason CancelReason `xml:" CancelReason"`
}
// Must match the pattern \d{14}
type AmazonOrderItemCode string
The type name is Anon1 due to #14
from go-xml.
So a couple things:
- xsdgen (command nor package) doesn't fetch dependent schema for you; you have to specify all relevant files on the command line. Resolving all dependencies recursively would be a good feature (or separate command). Sometimes that's hard because the
<import>
or<include>
statements don't have consistent URIs (or none at all). - There's a bug in lookupTargetNS that necessitated the
-ns ""
workaround. I neglected to consider the case when no target namespace is considered.
from go-xml.
@droyo Thank you! With -ns ""
I was able to generate Go file. I think, this issue can be closed now.
from go-xml.
Related Issues (20)
- Unconvertable xsd schema HOT 2
- Add "Code generated ..." comment line automatically HOT 1
- Allow wsdlgen to take build tags HOT 2
- xsdgen: gen type "measResults": Unknown built-in type "anySimpleType" HOT 6
- Timezone is not considered in MarshalText method HOT 4
- Schema with restriction and base="xsd:dateTime" HOT 1
- Unable to unmarshal embedded xhtml HOT 3
- could not find base type anySimpleType in namespace http://www.w3.org/2001/XMLSchema HOT 3
- Cannot use non-namespaced (but included) types in schema HOT 4
- complexType DetailedHashSum: could not find type "BinaryDataType" in namespace http://service.ddex.net/xml/avs/avs for element DataType HOT 3
- complexType localElement: could not find type in namespace for attribute substitutionGroup HOT 11
- utf-8 name in xsd HOT 3
- Issue with `type="xsd:date" maxOccurs="unbounded"` HOT 1
- Failed to parse chardata. HOT 2
- Element ref not generating and linking types correctly. HOT 3
- question about walking the xsd HOT 3
- Does not generate code HOT 1
- Tests generated for `gentests/books/books_test.go` do not pass
- replace rule not working to create shared types
- aqwari.net is down HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-xml.