It appears that the integrity of the namespaces are not maintained per the definition of xs:import.
I believe that when using xs:import, the namespace of the imported XSD is maintained within the host xsd that is importing. It appears that xs:import is handled like an xs:include in the code, which is incorrect.
so, given:
1) 'AFile.xsd' with element 'A1' typed as a complexType 'A1c' and a namespace of 'An'
2) 'BFile.xsd' with element 'B1' typed as complexType B1c and a namespace of 'Bn' that imports AFile.xsd
Per the spec BFile should have :
An:A1
An:A1c
Bn:B1
Bn:B1c
But the code shows :
Bn:A1
Bn:A1c
Bn:B1
BnB1c
Note this code :
In 'process_includes.py' note function 'clear_includes_and_imports(node)'
function treats xs:includes and xs:imports both as an xs:include
Robert,
Not too sure, but I do not believe I have yet been able to reproduce
your problem.
I've attached files that I created and used for my tests.
When I test with these files, here is what I did and what I see:
That seems right, but maybe not what you are trying to report.
Can you tell me how I need to modify my test files in order to
reproduce the issue you are reporting. Thanks for any help.
And, by the way, I agree with you that there must be something amiss
where
process_includes.pyis treatingxs:includeandxs:importthe same way. A bit of excuse making -- that code was written years
ago when I understood XML name spaces even more poorly than I do now.
Dave
Hi Dave,
The approach appears to walk recursively across the imports and includes and flatten into one tree. The problem is how the flattening is done. It appears that imports are treated in the same manner as includes. Per the spec, included constructs use the host xsd namespace. However, imports should maintain their native namespaces in the host xsd.
This becomes an issue when you have two or more elements with the same name in two or more imported xsds. I end up with collisions. Also a problem when generating code. I would want to generate code for each construct with their respective namespace.
To see the issue added code (in prep_schema) at line 38-41 "# ADD THIS THIS ***"
Note: infile has been opened in binary mode.
37.
ADD THIS THIS ***
*****
43.
dbg
print('\nmapping:')
for item in rename_data.name_mappings.items():
print(' {}'.format(item))
print('\n')
end prep_schema_doc
This is the flatten xsd :
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:an="http://example.org/namespaceA" xmlns:bn="http://example.org/namespaceB" targetnamespace="http://example.org/namespaceB">
<xs:element name="B1" type="bn:B1c">
<xs:element name="AB1" type="bn:A1c">
<xs:complextype name="A1c1">
<xs:sequence>
<xs:element name="fieldaa1" type="xs:string">
<xs:element name="fieldaa2" type="xs:integer">
<xs:element name="fieldaa3" type="an:A1c">
</xs:element></xs:element></xs:element></xs:sequence>
</xs:complextype>
<xs:complextype name="B1c">
<xs:sequence>
<xs:element name="fieldB1" type="xs:string">
<xs:element name="fieldB2" type="xs:integer">
<xs:element name="fieldB3" type="an:A1c">
</xs:element></xs:element></xs:element></xs:sequence>
</xs:complextype></xs:element></xs:element></xs:schema>
<xs:element name="A1" type="an:A1c">
<xs:complextype name="A1c">
<xs:sequence>
<xs:element name="fieldA1" type="xs:string">
<xs:element name="fieldA2" type="xs:integer">
</xs:element></xs:element></xs:sequence>
</xs:complextype></xs:element>
Note :
<xs:complextype name="A1c">
<xs:sequence>
<xs:element name="fieldA1" type="xs:string">
<xs:element name="fieldA2" type="xs:integer">
</xs:element></xs:element></xs:sequence>
</xs:complextype>
Is not scoped by http://example.org/namespaceA
Also note :
<xs:element name="AB1" type="bn:A1c"></xs:element>
AB1 is now defined as :
<xs:complextype name="A1c">
<xs:sequence>
<xs:element name="fieldA1" type="xs:string">
<xs:element name="fieldA2" type="xs:integer">
</xs:element></xs:element></xs:sequence>
</xs:complextype>
But was originally defined as :
<xs:complextype name="A1c">
<xs:sequence>
<xs:element name="fieldaa1" type="xs:string">
<xs:element name="fieldaa2" type="xs:integer">
<xs:element name="fieldaa3" type="an:A1c">
</xs:element></xs:element></xs:element></xs:sequence>
</xs:complextype>
From: Dave Kuhlman dkuhlman@users.sourceforge.net
Sent: Monday, September 14, 2020 6:30 PM
To: [generateds:tickets] 4@tickets.generateds.p.re.sourceforge.net
Subject: [generateds:tickets] #4 XS:Imports Namespace lost
Robert,
Not too sure, but I do not believe I have yet been able to reproduce
your problem.
I've attached files that I created and used for my tests.
When I test with these files, here is what I did and what I see:
$ ./generateDS.py -o testmod.py bfile.xsd
$ python testmod.py test01.xml
<bn:b1 xmlns:bn="http://example.org/namespaceB"></bn:b1>
That seems right, but maybe not what you are trying to report.
Can you tell me how I need to modify my test files in order to
reproduce the issue you are reporting. Thanks for any help.
And, by the way, I agree with you that there must be something amiss
where process_includes.py is treating xs:include and xs:import
the same way. A bit of excuse making -- that code was written years
ago when I understood XML name spaces even more poorly than I do now.
Dave
Attachments:
[tickets:#4]https://sourceforge.net/p/generateds/tickets/4/ XS:Imports Namespace lost
Status: open
Milestone: 1.0
Created: Sun Sep 13, 2020 05:37 PM UTC by Robert F Lario
Last Updated: Sun Sep 13, 2020 05:37 PM UTC
Owner: Dave Kuhlman
It appears that the integrity of the namespaces are not maintained per the definition of xs:import.
I believe that when using xs:import, the namespace of the imported XSD is maintained within the host xsd that is importing. It appears that xs:import is handled like an xs:include in the code, which is incorrect.
so, given:
1) 'AFile.xsd' with element 'A1' typed as a complexType 'A1c' and a namespace of 'An'
2) 'BFile.xsd' with element 'B1' typed as complexType B1c and a namespace of 'Bn' that imports AFile.xsd
Per the spec BFile should have :
An:A1
An:A1c
Bn:B1
Bn:B1c
But the code shows :
Bn:A1
Bn:A1c
Bn:B1
BnB1c
Note this code :
In 'process_includes.py' note function 'clear_includes_and_imports(node)'
function treats xs:includes and xs:imports both as an xs:include
Sent from sourceforge.net because you indicated interest in https://sourceforge.net/p/generateds/tickets/4/
To unsubscribe from further messages, please visit https://sourceforge.net/auth/subscriptions/
Related
Tickets:
#4Robert,
Looking at this again.
I generated a module with this:
--member-specs=dict --export="write etree validate" bfile.xsd
I suspect that you are right, and that there is a problem here.
Perhaps namespaces and namespace prefixes will not be produced
correctly during export.
However, when I generate a module from the modified
bfile.xsdandafile.xsd. I do not get name collisions. I see that we generateclasses
A1c,A1c1, andB1c. As you mention below, classA1c1, in this case, is the complex type defined in schemabfile.xsd. It has been renamed in order to avoid use of aduplicate name. One of the reasons for this renaming is that we
must generate all these classes in a single Python namespace.
Class
A1c1has a member variable that contains instances of classA1c(the one defined in namespacean).Near the bottom of the generated module, you will find something
like this:
This is intended to tell you what gets renamed to what. For one, it
could help you determine that, if you want to create an instance of
your new added element
AB1, you need to create an instance ofclass
A1c1, which is the renamed one from namespacehttp://example.org/namespaceB.So, that renaming, again that you refer in your message, is
intended. It may not be ideal, but it's the best that
generateDS.pycan do with duplicate names in multiple namespaces.And, actually, it took me a long time to implement something that
was even that good (or less bad).
Does that help? Please let me know if your think there is still
something wrong, perhaps something I've missed?
Dave
On Tue 15 Sep 2020 12:38:18 PM PDT, Robert F Lario wrote:
--
Dave Kuhlman
http://www.davekuhlman.org
Related
Tickets:
#4Robert,
Looking at this again.
I generated a module with this:
I suspect that you are right, and that there is a problem here.
Perhaps namespaces and namespace prefixes will not be produced
correctly during export.
However, when I generate a module from the modified
bfile.xsdandafile.xsd. I do not get name collisions. I see that we generateclasses
A1c,A1c1, andB1c. As you mention below, classA1c1, in this case, is the complex type defined in schemabfile.xsd. It has been renamed in order to avoid use of aduplicate name. One of the reasons for this renaming is that we
must generate all these classes in a single Python namespace.
Class
A1c1has a member variable that contains instances of classA1c(the one defined in namespacean).Near the bottom of the generated module, you will find something
like this:
This is intended to tell you what gets renamed to what. For one, it
could help you determine that, if you want to create an instance of
your new added element
AB1, you need to create an instance ofclass
A1c1, which is the renamed one from namespacehttp://example.org/namespaceB.So, that renaming, again that you refer in your message, is
intended. It may not be ideal, but it's the best that
generateDS.pycan do with duplicate names in multiple namespaces.And, actually, it took me a long time to implement something that
was even that good (or less bad).
Does that help? Please let me know if your think there is still
something wrong, perhaps something I've missed?
Dave