Daniel,
Thank you for reporting this and for tracking down and analyzing the
problem.
The constructor for XschemaAttribute should not be using a hardwired
XML schema namespace prefix. That's what the global variables
StringType, IntegerType, etc. are for. So, I've initialized that
parameter to StringType[0], which in your case (using -a "xsd:")
will have the value "xsd:string" (instead of the incorrect value
"xs:string").
I've attached a patch. I've also pushed this change to
https://bitbucket.org/dkuhlman/generateds.
I believe that your fix would have worked, too. But, I prefer mine.
Don't know why.
Thanks again for your help.
Dave
On Fri, Aug 03, 2018 at 09:49:13AM +0000, Ramirez, Daniel - FAS GmbH wrote:
> Hi again Dave,
>
>
> I am trying to generate bindings with a quite big XSD file and I get one
> error regarding xs:string when I have no xs: namespace. I tried to track down
> the problem.
>
>
> * Here you have the command line:
>
>
> (env) ? python env\Scripts\generateDS.py -a "xsd:" -f -m -o
> autosar_bindings\r44\bindings.py xsd\autosar-00044-strict-compact.xsd
> Traceback (most recent call last):
> File "env\Scripts\generateDS.py", line 7544, in <module>
> main()
> File "env\Scripts\generateDS.py", line 7526, in main
> superModule=superModule)
> File "env\Scripts\generateDS.py", line 7002, in parseAndGenerate
> prefix, root, options, args, superModule)
> File "env\Scripts\generateDS.py", line 6812, in generate
> generateFromTree(wrt, prefix, elements, processed)
> File "env\Scripts\generateDS.py", line 6681, in generateFromTree
> generateClasses(wrt, prefix, element, 0, nameSpacesDef)
> File "env\Scripts\generateDS.py", line 5032, in generateClasses
> generateCtor(wrt, prefix, element)
> File "env\Scripts\generateDS.py", line 4221, in generateCtor
> fullyQualifiedType = attrDef.getFullyQualifiedTypeName()
> File "env\Scripts\generateDS.py", line 1478, in getFullyQualifiedTypeName
> return prefixToNamespaceMap[prefix] + ":" + value
> KeyError: 'xs'
>
> * I managed to track the problem to the line 1343 in version 2.29.19,
> where
>
> newAttr = XschemaAttribute(newName)
>
> * The case, for what I see in the code, is that my XSD has the same name
> for an element and for an attribute, so it triggers the fix_dup_names() code
> * The default datatype there is xs:string but prefixToNamespaceMap has no
> "xs" entry as my XSD has no "xs" reference, so it crashes.
> * I think of some solutions here:
> * a "default xs" entry could exist in the dictionary if you keep
> "xs:string" as default
> * instead of "xs:string", make the data_type parameter in
> XschemaAttribute mandatory, without default (I sort of like this one)
> * some config parameter to define the default
> * I patched my version like this:
>
> newAttr = XschemaAttribute(newName, data_type=attr.getData_type())
>
> My problem is, again, I do not know if I am breaking something.
>
> I hope I explained myself :S
>
> Thanks again,
> Dani
>
> Daniel Ramirez
> Software Development
> FAS GmbH
> Frühlingstraße 31-33 - 85055 Ingolstadt
> Mobil: +49-(0) 152-21700-621
> Email:
> daniel.rami...@fahrerassistenzsysteme.de<mailto:daniel.rami...@fahrerassistenzsysteme.de>
--
Dave Kuhlman
http://www.davekuhlman.org
diff -r ce334cfc1514 generateDS.py
--- a/generateDS.py Thu Aug 02 12:53:00 2018 -0700
+++ b/generateDS.py Fri Aug 03 14:44:10 2018 -0700
@@ -227,7 +227,7 @@
# Do not modify the following VERSION comments.
# Used by updateversion.py.
##VERSION##
-VERSION = '2.29.21'
+VERSION = '2.29.22'
##VERSION##
BaseStrTypes = six.string_types
@@ -442,6 +442,8 @@
IDTypes = (IDREFSType, IDREFType, IDType, )
SchemaType = nameSpace + 'schema'
SequenceType = nameSpace + 'sequence'
+ # The firist item in this tuple is special.
+ # It's the primary string type and must stay in the first position.
StringType = (
nameSpace + 'string',
nameSpace + 'duration',
@@ -1440,12 +1442,15 @@
def __init__(
self,
name,
- data_type='xs:string',
+ data_type=None,
use='optional',
default=None,
fixed=None):
self.name = name
- self.data_type = data_type
+ if data_type is None:
+ self.data_type = StringType[0]
+ else:
+ self.data_type = data_type
self.use = use
self.default = default
# treat `fixed` the same as `default`.
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
generateds-users mailing list
generateds-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/generateds-users