Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

definitions of xmlns:xsi and xmlns:qdt in rsm:CrossIndustryInvoice missing #42

Open
lka opened this issue Oct 8, 2024 · 6 comments
Open

Comments

@lka
Copy link

lka commented Oct 8, 2024

Version 2.4.0 from pypi
Expected:

<rsm:CrossIndustryInvoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:qdt="urn:un:unece:uncefact:data:standard:QualifiedDataType:100"
xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100"
xmlns:rsm="urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100"
xmlns:ram="urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100">
rsm:ExchangedDocumentContext
ram:GuidelineSpecifiedDocumentContextParameter
ram:IDurn:cen.eu:en16931:2017#compliant#urn:xoev-de:kosit:standard:xrechnung_2.3</ram:ID>
</ram:GuidelineSpecifiedDocumentContextParameter>
</rsm:ExchangedDocumentContext>
rsm:ExchangedDocument
....

but got:

<rsm:CrossIndustryInvoice
xmlns:ram="urn:un:unece:uncefact:data:standard:ReusableAggregateBusinessInformationEntity:100"
xmlns:rsm="urn:un:unece:uncefact:data:standard:CrossIndustryInvoice:100"
xmlns:udt="urn:un:unece:uncefact:data:standard:UnqualifiedDataType:100">
rsm:ExchangedDocumentContext
ram:GuidelineSpecifiedDocumentContextParameter
ram:IDurn:cen.eu:en16931:2017#conformant#urn:factur-x.eu:1p0:extended</ram:ID>
</ram:GuidelineSpecifiedDocumentContextParameter>
</rsm:ExchangedDocumentContext>
...

ValiTool said:
Das XML ist valide.

Profil: urn:cen.eu:en16931:2017#conformant#urn:factur-x.eu:1p0:extended
Korrekte XML Struktur: OK
Korrektes XML Schema: OK
Korrekte XML Namespaces: OK
Korrekte XML Kodierung: OK
Korrekte Code Listen: OK
Gibt es Warnungen? Ja

Details

[VD-Valitool-14]-Der Namespace xmlns:qdt fehlt. Auch wenn dieser in der Instanzdatei nicht benötigt wird, sollte dieser gemäß Spezifikation angegeben werden.

did I forgot something to initialize or is it a failure?

@raphaelm
Copy link
Member

Probably a bug, but maybe hard to fix if the XML library we use only adds namespaces that are needed

@lka
Copy link
Author

lka commented Nov 19, 2024

Thanks for the answer.
In the moment i’m using a workaround. After creating the XML and before attaching it to the pdf i use a brute force method to add the namespace i expect if it doesn‘t exist.
ValiTool has no more problems with this.

@bwurst
Copy link

bwurst commented Nov 19, 2024

I'm also interested in a solution to this validator error. How do you add namespaces after creation? Just with text based file manipulation?

@lka
Copy link
Author

lka commented Nov 19, 2024

from drafthorse.models import NS_QDT
….
xml = self.modify_xml(self.doc.serialize(schema="FACTUR-X_EXTENDED"))
….

def modify_xml(self, xml=None):
        """insert xmlns:qdt if it is not in namespaces"""
        decoded = xml.decode('utf-8')
        searchstr = re.search(r'<rsm:CrossIndustryInvoice(.*)>',
                              decoded).group()
        # print(searchstr)
        nsmap = searchstr.split(' ')
        _QDT = 'xmlns:qdt='
        if _QDT not in nsmap:
            QDT = _QDT + '\"' + NS_QDT + '\"'
            nsmap.insert(1, QDT)
            decoded = decoded.replace(searchstr, ' '.join(nsmap))
        # print ('MAP:', nsmap)

        return decoded.encode('utf-8')

@bwurst
Copy link

bwurst commented Nov 20, 2024

Thank you for the pointer. Your if statement does not work when attribute is present, so I modified that part to

    _QDT = 'xmlns:qdt='
    QDT = _QDT + '\"' + NS_QDT + '\"'
    if QDT not in nsmap:
        ...

@lka
Copy link
Author

lka commented Nov 20, 2024

you are right, thanks
verified and modified in my own code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants