架构验证失败; XML 不符合符合 ZATCA 规范的 UBL 2.1 标准

问题描述 投票:0回答:3

我正在尝试使用符合沙特阿拉伯 ZATCA(天课,税务和海关当局)规范的 UBL 2.1 标准来验证我的 xml。此验证的网址:https://sandbox.zatca.gov.sa/TestXML但我无法验证这一点,因为我的 xml 看起来很棒,但我不明白出了什么问题。我使用 python json2xml 包来创建 xml。这个包从 json 生成 xml。

错误列出了我从 ZATCA XML Validator 获得的内容:

类别:XSD_SCHEMA_ERROR

代码:SAXParseException

消息:架构验证失败; XML 不符合符合 ZATCA 规范的 UBL 2.1 标准

这是我的Xml代码:

   <?xml version="1.0" ?>
<Invoice>
    <ProfileID>reporting:1.0</ProfileID>
    <ID>INV004</ID>
    <UUID>fd5a7cc4-2316-49ee-ac07-6f4be4be3731</UUID>
    <IssueDate>2022-08-13</IssueDate>
    <IssueTime>23:46:07</IssueTime>
    <InvoiceTypeCode>388</InvoiceTypeCode>
    <InvoiceTypeCodeName>0101001</InvoiceTypeCodeName>
    <DocumentCurrencyCode>SAR</DocumentCurrencyCode>
    <TaxCurrencyCode>SAR</TaxCurrencyCode>
    <Note/>
    <OrderReference>
        <ID/>
    </OrderReference>
    <ContractDocumentReference>
        <ID/>
    </ContractDocumentReference>
    <AdditionalDocumentReference>
        <UUID>4</UUID>
        <PIH>
            <Attachment>
                <EmbeddedDocumentBinaryObject>ET05jV7roub7D66wOAQ49TQ8mCkyldhmH7B8CV3Rc6g=</EmbeddedDocumentBinaryObject>
            </Attachment>
        </PIH>
        <QR>
            <Attachment>
                <EmbeddedDocumentBinaryObject>5D6ZU7f6nb+s1szmMw46l4NZ7yTy0p1wi0ZUMsdQWBE=</EmbeddedDocumentBinaryObject>
            </Attachment>
        </QR>
    </AdditionalDocumentReference>
    <Signature>
        <ID>urn:oasis:names:specification: ubl:signature:Invoice</ID>
        <SignatureMethod>urn:oasis:names:specification:ubl:dsig:enveloped: xades</SignatureMethod>
    </Signature>
    <AccountingSupplierParty>
        <Party>
            <PartyLegalEntity>
                <RegistrationName>Altaf Miazee</RegistrationName>
            </PartyLegalEntity>
            <PartyIdentification>
                <ID/>
            </PartyIdentification>
            <PartyTaxScheme>
                <CompanyID>300600363600003</CompanyID>
            </PartyTaxScheme>
            <PostalAddress>
                <Country>
                    <IdentificationCode>BD</IdentificationCode>
                </Country>
                <AdditionalStreetName>Altafbari</AdditionalStreetName>
                <StreetName>dhaka</StreetName>
                <BuildingNumber>1233</BuildingNumber>
                <PlotIdentification>1233</PlotIdentification>
                <CityName>Dhaka</CityName>
                <PostalZone>12302</PostalZone>
                <CountrySubentity>Dhaka</CountrySubentity>
                <CitySubdivisionName>miazee</CitySubdivisionName>
            </PostalAddress>
        </Party>
    </AccountingSupplierParty>
    <AccountingCustomerParty>
        <Party>
            <PartyLegalEntity>
                <RegistrationName>Hosen MD Altaf</RegistrationName>
            </PartyLegalEntity>
            <PartyIdentification>
                <ID>398765409876333</ID>
            </PartyIdentification>
            <PartyTaxScheme>
                <CompanyID>398765409876333</CompanyID>
            </PartyTaxScheme>
            <PostalAddress>
                <StreetName>الملك سلمان</StreetName>
                <AdditionalStreetName>الملك سلمان</AdditionalStreetName>
                <BuildingNumber>1234</BuildingNumber>
                <PlotIdentification>1234</PlotIdentification>
                <CityName>dhaka</CityName>
                <PostalZone>12234</PostalZone>
                <CountrySubentity>Dhaka</CountrySubentity>
                <CitySubdivisionName>الملك سلمان</CitySubdivisionName>
                <Country>
                    <IdentificationCode>BD</IdentificationCode>
                </Country>
            </PostalAddress>
        </Party>
    </AccountingCustomerParty>
    <Delivery>
        <ActualDeliveryDate>2022-08-25</ActualDeliveryDate>
        <LatestDeliveryDate/>
    </Delivery>
    <PaymentMeans>
        <PaymentMeansCode>10</PaymentMeansCode>
        <PayeeFinancialAccount>
            <PaymentNote/>
        </PayeeFinancialAccount>
    </PaymentMeans>
    <AllowanceCharge>
        <TaxCategory>
            <ID>S</ID>
            <Percent>0.0</Percent>
            <TaxScheme>
                <ID>VAT</ID>
            </TaxScheme>
        </TaxCategory>
        <ChargeIndicator>False</ChargeIndicator>
        <MultiplierFactorNumeric>52.1</MultiplierFactorNumeric>
        <Amount>0.00</Amount>
        <AmountcurrencyID>SAR</AmountcurrencyID>
        <BaseAmount>164263.68</BaseAmount>
        <BaseAmountcurrencyID>SAR</BaseAmountcurrencyID>
    </AllowanceCharge>
    <LegalMonetaryTotal>
        <LineExtensionAmount>164263.68</LineExtensionAmount>
        <LineExtensionAmountCurrencyID>SAR</LineExtensionAmountCurrencyID>
        <AllowanceTotalAmount>0.00</AllowanceTotalAmount>
        <AllowanceTotalAmountcurrencyID>SAR</AllowanceTotalAmountcurrencyID>
        <TaxExclusiveAmount>146664.00</TaxExclusiveAmount>
        <TaxExclusiveAmountcurrencyID>SAR</TaxExclusiveAmountcurrencyID>
        <TaxInclusiveAmount>164263.68</TaxInclusiveAmount>
        <TaxInclusiveAmountcurrencyID>SAR</TaxInclusiveAmountcurrencyID>
        <PrepaidAmount/>
        <PrepaidAmountcurrencyID>SAR</PrepaidAmountcurrencyID>
        <PayableAmount>164263.68</PayableAmount>
        <PayableAmountcurrencyID>SAR</PayableAmountcurrencyID>
    </LegalMonetaryTotal>
    <TaxTotal>
        <TaxAmount>17599.68</TaxAmount>
        <VatAmountCurrency>SAR</VatAmountCurrency>
        <VatAmountInAccountingCurrency>17599.68</VatAmountInAccountingCurrency>
        <CurrencyForVatAmountInAccountingCurrency>SAR</CurrencyForVatAmountInAccountingCurrency>
        <TaxSubtotal>
            <TaxableAmount>146664.0</TaxableAmount>
            <TaxableAmountcurrencyID>SAR</TaxableAmountcurrencyID>
            <TaxCategory>
                <ID>E</ID>
                <Percent>1</Percent>
                <TaxExemptionReasonCode>TYIEWE</TaxExemptionReasonCode>
                <TaxExemptionReason>lksdkskak</TaxExemptionReason>
                <TaxScheme>
                    <ID>10.12</ID>
                </TaxScheme>
            </TaxCategory>
            <TaxAmountcurrencyID>SAR</TaxAmountcurrencyID>
        </TaxSubtotal>
        <TaxAmountcurrencyID>SAR</TaxAmountcurrencyID>
    </TaxTotal>
    <InvoiceLine>
        <item>
            <ID>1</ID>
            <InvoicedQuantity>12</InvoicedQuantity>
            <InvoicedQuantityUnitCode>nos</InvoicedQuantityUnitCode>
            <LineExtensionAmount>146664.0</LineExtensionAmount>
            <LineExtensionAmountcurrencyID>SAR</LineExtensionAmountcurrencyID>
            <AllowanceCharge>
                <ChargeIndicator>False</ChargeIndicator>
                <MultiplierFactorNumeric>0.0</MultiplierFactorNumeric>
                <Amount>0</Amount>
                <AmountcurrencyID>SAR</AmountcurrencyID>
                <BaseAmount>146664.0</BaseAmount>
                <BaseAmountcurrencyID>SAR</BaseAmountcurrencyID>
            </AllowanceCharge>
            <TaxTotal>
                <TaxAmount>17599.68</TaxAmount>
                <TaxAmountcurrencyID>SAR</TaxAmountcurrencyID>
                <RoundingAmount>164263.68</RoundingAmount>
                <RoundingAmountcurrencyID>SAR</RoundingAmountcurrencyID>
            </TaxTotal>
            <Item>
                <Name>altaf</Name>
                <BuyersItemIdentification>
                    <ID/>
                </BuyersItemIdentification>
                <SellersItemIdentification>
                    <ID>ITM9</ID>
                </SellersItemIdentification>
                <StandardItemIdentification>
                    <ID/>
                </StandardItemIdentification>
                <ClassifiedTaxCategory>
                    <ID>2</ID>
                    <Percent>12.00</Percent>
                    <TaxScheme>
                        <ID>VAT</ID>
                    </TaxScheme>
                </ClassifiedTaxCategory>
            </Item>
            <Price>
                <PriceAmount>12222.00</PriceAmount>
                <PriceAmountschemeID>SAR</PriceAmountschemeID>
                <AllowanceCharge>
                    <ChargeIdicator>False</ChargeIdicator>
                    <Amount>0</Amount>
                    <AmountcurrencyID>SAR</AmountcurrencyID>
                    <BaseAmount>164263.68</BaseAmount>
                    <BaseAmountcurrencyID>SAR</BaseAmountcurrencyID>
                </AllowanceCharge>
                <BaseQuantity>12</BaseQuantity>
                <BaseQuantityUnitCode/>
            </Price>
        </item>
    </InvoiceLine>
</Invoice>

这是我为创建 XML 编写的 Python 代码:

def download_invoice_xml(request, invoice_type, invoice_no):
in_data = InvoiceReport.objects.filter(invoice_type=invoice_type, invoice_number=invoice_no)
for inv in in_data:
    jsonData = inv.invoice_data
    mode = inv.creation_mode  

# Issuetime = jsonData['IssueTime']
# d1 = datetime.strptime(Issuetime, "%Y-%m-%dT%H:%M:%S")
# dt_to_string = d1.strftime('%d-%m-%Y %H:%M:%S')
# jsonData['IssueTime'] = dt_to_string
#
# Issuedate = jsonData['IssueDate']
# d2 = datetime.strptime(Issuedate, "%Y-%m-%d")
# dt_to_string2 = d1.strftime('%d-%m-%Y')
# jsonData['IssueDate'] = dt_to_string2
if jsonData.get('AllowanceCharge').get('ChargeIndicator') == 0:
    jsonData['AllowanceCharge']['ChargeIndicator'] = False
for i in jsonData.get('InvoiceLine'):
    if i.get('AllowanceCharge').get('ChargeIndicator') == 0:
        i['AllowanceCharge']['ChargeIndicator'] = False
    if i.get('Price').get('AllowanceCharge').get('ChargeIndicator') == 0:
        i['Price']['AllowanceCharge']['ChargeIndicator'] = False
xml_output = json2xml.Json2xml(jsonData, wrapper="Invoice", pretty=True, attr_type=False).to_xml()

now = datetime.now()
if xml_output:
    response = HttpResponse(xml_output, content_type='application/xml')
    xml_date = jsonData['IssueDate'].replace("-", "")
    xml_time = jsonData['IssueTime'].replace(":", "")
    filename = jsonData['AccountingSupplierParty']['Party']['PartyTaxScheme']['CompanyID'] + "_" + \
               xml_date + "T" + xml_time + "_" + str(jsonData['ID']) + ".xml"
    # filename = jsonData['AccountingSupplierParty']['Party']['PartyIdentification']['ID'] + "_%s_%s.xml" % (
    #     str((now.strftime("%Y%m%d%H%M%S"))), jsonData['ID'])      
    content = "attachment; filename=%s" % (filename)
    response['Content-Disposition'] = content
    return response
return HttpResponse("Not found")

这是ZATCA电子发票系统的一部分,项目代码是用python django编写的。

python django xml xsd xml-parsing
3个回答
4
投票

未满足的UBL规范通常分为两类:

    属性是必需的,但您没有提供。
  1. 元素内属性的顺序错误。
要解决您的问题,您应该根据 UBL Schema 规范检查 XML 的每个元素,并找到您未提供的必需属性或乱序的属性..

  • 访问列出了 UBL 规格的网站:

    http://www.datypic.com/sc/ubl21/ss.html

  • 在顶部的搜索框中,输入元素名称,后跟单词“类型”(例如:发票 --> 搜索 InvoiceType

enter image description here

    在元素规范中,找到其关系以 [1 .. 该属性是强制性的,请确保为其提供一个值。
  • enter image description here
  • 检查属性的顺序并确保它们以正确的顺序添加。
  • enter image description here
这样做将确保您的所有元素都符合 UBL 规范。



0
投票
看起来名称空间已在 XML 中丢失。 请参阅 OASIS 网站上的示例。

例如:

UBL-Invoice-2.1-Example-Trivial.xml(下文有删节),使用前缀“cac”和“cbc”(映射到根元素中的 URI):

<?xml version="1.0" encoding="UTF-8"?> <Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"> <cbc:ID>123</cbc:ID> <cbc:IssueDate>2011-09-22</cbc:IssueDate> <cac:InvoicePeriod> <cbc:StartDate>2011-08-01</cbc:StartDate> <cbc:EndDate>2011-08-31</cbc:EndDate> </cac:InvoicePeriod> <!-- ... --> </Invoice>
    
© www.soinside.com 2019 - 2024. All rights reserved.