"NamespaceUniquenessError: name used for multiple values in typeBinding

Help
2016-11-24
2016-11-24
  • Douglas silva

    Douglas silva - 2016-11-24

    Hi there!

    I have had an issue when i'm using generated bindings.

    I generated 2 binding files:
    leiauteCCe.py -> leiauteCCe.xsd
    leiauteCanc.py -> leiauteCanc.xsd

    using the following commands:

    pyxbgen -u resources/PL_008f/tiposBasico_v3.10.xsd -m tipos_basicos --archive-path .:+

    pyxbgen -u resources/PL_008f/leiauteCCe.xsd -m leiauteCCe --archive-path .:+

    pyxbgen -u resources/PL_008f/leiauteCanc.xsd -m leiauteCanc --archive-path .:+

    Till this point everything is ok.

    However, when i'm trying to use them an exception is raised:
    "NamespaceUniquenessError: http://www.portalfiscal.inf.br/nfe: name TVerEnvEvento used for multiple values in typeBinding"

    I was wondering why that occur, so i discovered that both .xsd have the same complextypes, but these complextypes have different elements (because of this they are different files).

    Both files are in the following link:
    leiauteCCe.xsd -> https://gist.github.com/anonymous/0752883abe976db6a6750ee5c55482c3
    leiauteCanc.xsd -> https://gist.github.com/anonymous/bc8402dd6b7e954db1522d29d488b951

    Also, i see that pyxb generated two classes which points to different XSDLocation:
    leiauteCCe.py

    # Atomic simple type: {http://www.portalfiscal.inf.br/nfe}TVerEnvEvento
    class TVerEnvEvento (pyxb.binding.datatypes.string):
    
        """Tipo Versão do EnvEvento"""
    
        _ExpandedName = pyxb.namespace.ExpandedName(Namespace, 'TVerEnvEvento')
        _XSDLocation = pyxb.utils.utility.Location('/home/douglas/project/leiauteCCe.xsd', 340, 1)
        _Documentation = 'Tipo Vers\xe3o do EnvEvento'
    TVerEnvEvento._CF_pattern = pyxb.binding.facets.CF_pattern()
    TVerEnvEvento._CF_pattern.addPattern(pattern='1\\.00')
    TVerEnvEvento._CF_whiteSpace = pyxb.binding.facets.CF_whiteSpace(value=pyxb.binding.facets._WhiteSpace_enum.preserve)
    TVerEnvEvento._InitializeFacetMap(TVerEnvEvento._CF_pattern,
       TVerEnvEvento._CF_whiteSpace)
    Namespace.addCategoryObject('typeBinding', 'TVerEnvEvento', TVerEnvEvento)
    

    leiauteCanc.py

    # Atomic simple type: {http://www.portalfiscal.inf.br/nfe}TVerEnvEvento
    class TVerEnvEvento (pyxb.binding.datatypes.string):
    
        """Tipo Versão do EnvEvento"""
    
        _ExpandedName = pyxb.namespace.ExpandedName(Namespace, 'TVerEnvEvento')
        _XSDLocation = pyxb.utils.utility.Location('/home/douglas/project/leiauteCanc.xsd', 340, 1)
        _Documentation = 'Tipo Vers\xe3o do EnvEvento'
    TVerEnvEvento._CF_pattern = pyxb.binding.facets.CF_pattern()
    TVerEnvEvento._CF_pattern.addPattern(pattern='1\\.00')
    TVerEnvEvento._CF_whiteSpace = pyxb.binding.facets.CF_whiteSpace(value=pyxb.binding.facets._WhiteSpace_enum.preserve)
    TVerEnvEvento._InitializeFacetMap(TVerEnvEvento._CF_pattern,
       TVerEnvEvento._CF_whiteSpace)
    Namespace.addCategoryObject('typeBinding', 'TVerEnvEvento', TVerEnvEvento)
    

    Could someone help me fix it? I would be very glad :)

     
    Last edit: Douglas silva 2016-11-24
  • Peter A. Bigot

    Peter A. Bigot - 2016-11-24

    The NFe schema variants define incompatible information sets that have the same namespace. This is usually a bad idea, because given a document you need something other than the namespace to decode the document content.

    PyXB uses XML strictly, and will not allow you to use the same namespace for different document content in the same program. You can generate bindings for the Evento_CCe variant and use them in one program, and bindings for the Evento_Canc variant and use them in another program. You cannot have one program that uses both bindings, unless you change the namespace for one of the schema sets.

    A suggestion on how to build these schema: If you don't use --archive-to-file you don't gain anything by using --archive-path. Since the schema are incompatible, you're better off generating each one separately. It is inconvenient that they are split among multiple files with no file that includes all the components, so I suggest you create that file and use it to generate the bindings. Here's an example for the Evento_CCe bindings:

    lilith[55]$ cat CCe.xsd
    <xs:schema
        xmlns:xs="http://www.w3.org/2001/XMLSchema"
        xmlns="http://www.portalfiscal.inf.br/nfe"
        xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
        targetNamespace="http://www.portalfiscal.inf.br/nfe"
        elementFormDefault="qualified"
        attributeFormDefault="unqualified">
        <xs:include schemaLocation="CCe_v1.00.xsd"/>
        <xs:include schemaLocation="e110110_v1.00.xsd"/>
        <xs:include schemaLocation="envCCe_v1.00.xsd"/>
        <xs:include schemaLocation="procCCeNFe_v1.00.xsd"/>
        <xs:include schemaLocation="retEnvCCe_v1.00.xsd"/>
    </xs:schema>
    lilith[56]$ pyxbgen -u CCe.xsd -m CCe
    Python for http://www.portalfiscal.inf.br/nfe requires 2 modules
    lilith[57]$
    
     
    • Douglas silva

      Douglas silva - 2016-11-24

      Hey Peter, thanks so much for your help!

      Sorry for bothering you again, but even if i had two .xsd files like these:

      CCe.xsd

      <xs:schema
          xmlns:xs="http://www.w3.org/2001/XMLSchema"
          xmlns="http://www.portalfiscal.inf.br/nfe"
          xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
          targetNamespace="http://www.portalfiscal.inf.br/nfe"
          elementFormDefault="qualified"
          attributeFormDefault="unqualified">
          <xs:include schemaLocation="CCe_v1.00.xsd"/>
          <xs:include schemaLocation="e110110_v1.00.xsd"/>
          <xs:include schemaLocation="envCCe_v1.00.xsd"/>
          <xs:include schemaLocation="procCCeNFe_v1.00.xsd"/>
          <xs:include schemaLocation="retEnvCCe_v1.00.xsd"/>
      </xs:schema>
      

      Canc.xsd

      <xs:schema
          xmlns:xs="http://www.w3.org/2001/XMLSchema"
          xmlns="http://www.portalfiscal.inf.br/nfe"
          xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
          targetNamespace="http://www.portalfiscal.inf.br/nfe"
          elementFormDefault="qualified"
          attributeFormDefault="unqualified">
          <xs:include schemaLocation="eventoCancNFe_v1.00.xsd"/>
          <xs:include schemaLocation="e110111_v1.00.xsd"/>
          <xs:include schemaLocation="envEventoCancNFe_v1.00.xsd"/>
          <xs:include schemaLocation="procEventoCancNFe_v1.00.xsd"/>
          <xs:include schemaLocation="retEnvEventoCancNFe_v1.00.xsd"/>
      </xs:schema>
      

      I would have the same conflict beteween the base files leiauteCCe.xsd and leiauteCanc.xsd, am I right?

      So, the only way to have them running in the same program would be changing their namespaces, is it right?

      sorry again!

       
  • Peter A. Bigot

    Peter A. Bigot - 2016-11-24

    Yes. You have to change the targetNamespace attribute (which must match the attribute in the included schema). If you do that, the documents you read and write will have the new target namespace, which may cause other problems.

     
  • Douglas silva

    Douglas silva - 2016-11-24

    I got it! I'm gonna rename the namespace of one of the sets, then i'll manually override the namespace before sending the raw xml. Maybe this approach prevents problems caused by changing of namespace.

    Thank you so much again!

     
    Last edit: Douglas silva 2016-11-24
  • Douglas silva

    Douglas silva - 2016-11-24

    Hey peter that approach worked!!! :)
    Thank u guy!

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks