-
-
Notifications
You must be signed in to change notification settings - Fork 88
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
This closes #88, simpleType causing issues in the generated code #89
base: master
Are you sure you want to change the base?
Conversation
The line in the outer position of 'if' causes the simpleType element to be set to CurrentEle every time it is parsed. However, simpleType is not always the parent of all nested elements. If I have the following relationship: <element> -> <simpleType> -> [some element], then CurrentEle should be the element, not simpleType.
Good to say that, with this change, the output of the minimal XSD will be as follows: // Code generated by xgen. DO NOT EDIT.
package schema
// SomeComplexType ...
type SomeComplexType struct {
FirstElement int `xml:"FirstElement"`
ElementWithSimpleType *ElementWithSimpleType `xml:"ElementWithSimpleType"`
OtherElementWithSimpleType *OtherElementWithSimpleType `xml:"OtherElementWithSimpleType"`
ElementWithoutSimpleType int `xml:"ElementWithoutSimpleType"`
} Which is not the same as my expected output in the issue. (#88) This is because the issue related to the types parsing in the code shown is related to an another issue in the I'll send a PR to address this. |
This is related with <xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://example.com/schemas"
xmlns:xi="http://example.com/schemas"
elementFormDefault="qualified">
<xs:complexType name="SomeComplexType">
<xs:sequence>
<xs:element name="SomeElement">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value = "4" fixed = "true" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema> With the above XSD, putting on xgen, we get this output: // Code generated by xgen. DO NOT EDIT.
package schema
// SomeComplexType ...
type SomeComplexType struct {
SomeElement string `xml:"SomeElement"`
} Which is such correct. The problem comes when the // Code generated by xgen. DO NOT EDIT.
package schema
// SomeComplexType ...
type SomeComplexType struct {
SomeElement *SomeElement `xml:"SomeElement"`
} The To solve this, after our initial change, we can simply add this chunk of code in if opt.Element.Len() > 0 {
opt.Element.Peek().(*Element).Type, err = opt.GetValueType(valueType, protoTree)
return
} This occurs because the implementation of the // Code generated by xgen. DO NOT EDIT.
package schema
// SomeComplexType ...
type SomeComplexType struct {
SomeElement interface{} `xml:"SomeElement"`
} This is the actual unexpected behaviour. It occurs because the code was made around this, not solving the problem, just putting it off. The correct way to solve this is just remove all the following files:
With these changes, there is no reason to their existence. They all makes the same thing: solve the problem that was created before. After all, there is no issues with this elements. At least with all XSDs that I've tested. I didn't send any commit about all these deletions, because it is just it: delete them all. |
PR Details
Description
The line in the outer position of 'if' causes the
simpleType
element to be set toCurrentEle
every time it is parsed. However,simpleType
is not always the parent of all nested elements. If I have the following relationship as an example:then
CurrentEle
should be the element, not "simpleType". The attributename
defines the correct parent.With this, the problem occurs when
EndSimpleType
is called, becauseCurrentEle
is set to "simpleType", which it shouldn't be, incorrectly adding thissimpleType
element toProtoTree
.Related Issue
#88
Types of changes
Checklist