lib-cl-sii-python icon indicating copy to clipboard operation
lib-cl-sii-python copied to clipboard

(draft) dte.parse: `_set_dte_xml_missing_xmlns` does not support a non-root DTE XML element

Open glarrain opened this issue 5 years ago • 0 comments

The following will trigger an error:

import pathlib
from cl_sii.libs import xml_utils
from cl_sii.dte.parse import _set_dte_xml_missing_xmlns, DTE_XMLNS_MAP

file_path = pathlib.Path('SET_DTE_76408488-8_33_591.xml')
envio_dte_xml_doc = xml_utils.parse_untrusted_xml(file_path.read_bytes())
assert envio_dte_xml_doc.tag == '{http://www.sii.cl/SiiDte}EnvioDTE'

set_dte_em = xml_em.find('sii-dte:SetDTE', namespaces=DTE_XMLNS_MAP)
set_dte_em = envio_dte_xml_doc.find('sii-dte:SetDTE', namespaces=DTE_XMLNS_MAP)

dte_em_list = set_dte_em.findall('sii-dte:DTE', namespaces=DTE_XMLNS_MAP)
dte_em = dte_em_list[0]

_set_dte_xml_missing_xmlns(dte_em)
Exception: ('XML root element tag does not match the expected simple or namespaced name.', 'DTE', '{http://www.sii.cl/SiiDte}DTE', '{http://www.sii.cl/SiiDte}EnvioDTE')

For a file like this one (download this example set_dte_76408488-8_33_591.xml)

<?xml version="1.0" encoding="ISO-8859-1"?>
<EnvioDTE version="1.0" xmlns="http://www.sii.cl/SiiDte" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sii.cl/SiiDte EnvioDTE_v10.xsd">
<SetDTE ID="IDfc7f3b7ee3af4c078d300fd530656928">
<Caratula version="1.0">...</Caratula>
<DTE version="1.0">
<Documento ID="T33F591">...</Documento>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
</Signature>
</DTE>
</SetDTE>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
</Signature>
</EnvioDTE>

glarrain avatar May 14 '19 20:05 glarrain