Környezet / Environment
[x] https://api-test.onlineszamla.nav.gov.hu
HĂvott API operáciĂł / called API operation
[] /manageAnnulment
[x] /manageInvoice
[] /queryInvoiceChainDigest
[] /queryInvoiceCheck
[] /queryInvoiceData
[] /queryInvoiceDigest
[] /queryTransactionList
[] /queryTransactionStatus
[x] /queryTaxPayer
[] /tokenExchange
A kérés verziója / version of the request
[] 1.1
[] 2.0
[x] 3.0
A requestId értéke / requestId value
Today QueryTaxpayer 3EzQ4ZJdh2Oo5XwuIXqQU2uHgHMysE
Today ManageInvoices 4u2zd63Xdh00NlaNC3vEmeU2rTEcd1
Yesterday ManageInvoice 3BEE4kSyHsIhJHYPFnNEmDG3ICMTw0
A problĂ©ma rövid Ă©s tömör leĂrása / Clear and concise description of the problem
Starting from today the requests for ManageInvoice started failing due to namespace differences as we have strict checking for response namespace.
Could you please clarify why that is happening and whether discrepancies like this are to be expected?
I cannot find any documentation regarding this issue...
Egyéb tartalom / Additional content
TODAY
<ns2:QueryTaxpayerResponse xmlns="http://schemas.nav.gov.hu/NTCA/1.0/common" xmlns:ns2="http://schemas.nav.gov.hu/OSA/3.0/api" xmlns:ns3="http://schemas.nav.gov.hu/OSA/3.0/base" xmlns:ns4="http://schemas.nav.gov.hu/OSA/3.0/data">
<header>
<requestId>3EzQ4ZJdh2Oo5XwuIXqQU2uHgHMysE</requestId>
<timestamp>2021-01-06T12:06:49.262Z</timestamp>
<requestVersion>3.0</requestVersion>
<headerVersion>1.0</headerVersion>
</header>
<result>
<funcCode>OK</funcCode>
</result>
...
</ns2:QueryTaxpayerResponse>
TODAY
<ManageInvoiceResponse xmlns="http://schemas.nav.gov.hu/OSA/3.0/api" xmlns:ns2="http://schemas.nav.gov.hu/NTCA/1.0/common" xmlns:ns3="http://schemas.nav.gov.hu/OSA/3.0/base" xmlns:ns4="http://schemas.nav.gov.hu/OSA/3.0/data">
<ns2:header>
<ns2:requestId>4u2zd63Xdh00NlaNC3vEmeU2rTEcd1</ns2:requestId>
<ns2:timestamp>2021-01-06T12:06:49.515Z</ns2:timestamp>
<ns2:requestVersion>3.0</ns2:requestVersion>
<ns2:headerVersion>1.0</ns2:headerVersion>
</ns2:header>
<ns2:result>
<ns2:funcCode>OK</ns2:funcCode>
</ns2:result>
...
</ManageInvoiceResponse>
YESTERDAY
<ns2:ManageInvoiceResponse xmlns="http://schemas.nav.gov.hu/NTCA/1.0/common" xmlns:ns2="http://schemas.nav.gov.hu/OSA/3.0/api" xmlns:ns3="http://schemas.nav.gov.hu/OSA/3.0/base" xmlns:ns4="http://schemas.nav.gov.hu/OSA/3.0/data">
<header>
<requestId>3BEE4kSyHsIhJHYPFnNEmDG3ICMTw0</requestId>
<timestamp>2021-01-06T10:58:14.861Z</timestamp>
<requestVersion>3.0</requestVersion>
</header>
<result>
<funcCode>OK</funcCode>
</result>
...
</ns2:ManageInvoiceResponse>
Actually the xml document itself contains the namespace and prefix mapping as it should.
As you can see the first tag always lists the possible namespaces with the corresponding prefixes as xmlns attributes:
TODAY
<ns2:QueryTaxpayerResponse xmlns="http://schemas.nav.gov.hu/NTCA/1.0/common" xmlns:ns2="http://schemas.nav.gov.hu/OSA/3.0/api" xmlns:ns3="http://schemas.nav.gov.hu/OSA/3.0/base" xmlns:ns4="http://schemas.nav.gov.hu/OSA/3.0/data">
means that the xml will use the following prefixes:
| ns | prefix |
| -- | ------ |
| http://schemas.nav.gov.hu/NTCA/1.0/common | |
| http://schemas.nav.gov.hu/OSA/3.0/api | ns2 |
| http://schemas.nav.gov.hu/OSA/3.0/base | ns3 |
| http://schemas.nav.gov.hu/OSA/3.0/data | ns4 |
TODAY
<ManageInvoiceResponse xmlns="http://schemas.nav.gov.hu/OSA/3.0/api" xmlns:ns2="http://schemas.nav.gov.hu/NTCA/1.0/common" xmlns:ns3="http://schemas.nav.gov.hu/OSA/3.0/base" xmlns:ns4="http://schemas.nav.gov.hu/OSA/3.0/data">
means that the xml will use the following prefixes:
| ns | prefix |
| -- | ------ |
| http://schemas.nav.gov.hu/NTCA/1.0/common | ns2 |
| http://schemas.nav.gov.hu/OSA/3.0/api | |
| http://schemas.nav.gov.hu/OSA/3.0/base | ns3 |
| http://schemas.nav.gov.hu/OSA/3.0/data | ns4 |
YESTERDAY
<ns2:ManageInvoiceResponse xmlns="http://schemas.nav.gov.hu/NTCA/1.0/common" xmlns:ns2="http://schemas.nav.gov.hu/OSA/3.0/api" xmlns:ns3="http://schemas.nav.gov.hu/OSA/3.0/base" xmlns:ns4="http://schemas.nav.gov.hu/OSA/3.0/data">
means that the xml will use the following prefixes:
| ns | prefix |
| -- | ------ |
| http://schemas.nav.gov.hu/NTCA/1.0/common | |
| http://schemas.nav.gov.hu/OSA/3.0/api | ns2 |
| http://schemas.nav.gov.hu/OSA/3.0/base | ns3 |
| http://schemas.nav.gov.hu/OSA/3.0/data | ns4 |
Since the xml itself describes it's namespace mappings, there isn't any requirement or recommendation to have fixed prefixes thus you should never expect it to be static.
Every xml parser implementation should handle it. If you are handling xml-s as string you should first parse the xmlns attributes, then use the given mapping. (Or much better option is using an xml parser).
Dear @andrew-azarov
As @barchesz mentioned the namespace prefix is not fix.
Hello,
Our implementation handles it, but requires the namespace spec (and any proper XML parser should require it to) to select an element in a multinamespace XML document.
We use lxml and xpath in this particular instance.
First we setup namespace map
tempnsmap = {}
for namespace, namespaceurl in self.response.nsmap.items():
if not namespace: #default namespace
namespace = 'default'
tempnsmap[namespace] = namespaceurl
Then we select result code. According to your spec expected result code is contained in default namespace and result element default:result in the first element of such kind.
self.result = self.response.xpath('.//default:result', namespaces=self.nsmap)[0]
This is where we get an error because the namespace is inconsistent.
So I want to make sure whether namespace is going to be consistent (as per XML spec they should be) or not.
If namespaces are not consistent then we will have to parse the elements according to the structure and partial name.
I reverse lookup the prefixes by namespace URI, and use the found prefix to construct the xpath expression to get the value of funcCode.
Yeah actually the XSD specification doesn't say that the funcCode will be in the default namespace, it only declares that it's in the http://schemas.nav.gov.hu/NTCA/1.0/common regardless of what is the default or which prefix is used for that.
@barchesz that's pretty confusing and inconsistent, but whatever will detect the common one then by url.