Search code examples
xmlapache-axisxmlbeans

Axis2, XMLBeans and Government services - dealing with namespaces


So, I'm using Axis 2 to generate the stub classes from the WSDL files (with XMLBeans) and have also generated the entities from their XSD files.

Problem is: the envolope generated is something like this:

<?xml version='1.0' encoding='utf-8'?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
  <soapenv:Header>
    <nfeCabecMsg soapenv:mustUnderstand="false" xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeAutorizacao">
      <versaoDados>3.10</versaoDados>
      <cUF>51</cUF>
    </nfeCabecMsg>
  </soapenv:Header>
  <soapenv:Body>
    <nfeDadosMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NfeAutorizacao">
      <enviNFe versao="3.10" xmlns="http://www.portalfiscal.inf.br/nfe">
        <idLote>1</idLote>
        <indSinc>0</indSinc>
        <NFe>
          <!-- supressed -->
        </NFe>
      </enviNFe>
    </nfeDadosMsg>
  </soapenv:Body>
</soapenv:Envelope>

More specifically, the problem lays at this point:

<enviNFe versao="3.10" xmlns="http://www.portalfiscal.inf.br/nfe">
  <idLote>1</idLote>
  <indSinc>0</indSinc>
  <NFe>
    <!-- supressed -->
  </NFe>
</enviNFe>

But, for some random reason, they want it to be like this:

<enviNFe versao="3.10" xmlns="http://www.portalfiscal.inf.br/nfe">
  <idLote>1</idLote>
  <indSinc>0</indSinc>
  <NFe xmlns="http://www.portalfiscal.inf.br/nfe">
    <!-- supressed -->
  </NFe>
</enviNFe>

Yes, replicating the xmlns of the parent in just this one child, which I know makes no sense, but I have no control over it.

To prevent other craziness, I'm already replacing code inside the generated stub class, more precisely, I'm adding the setUseDefaultNamespace option.

I tried some hypothesis to fix this, but none work. How can I do that?


Solution

  • I ended up changing the generated .java files.

    The problem seems to be the provided wsdl's.