名前空間が定義されたXML文書をPythonで作成

Views: 97

Open Peoolの電子インボイスデータは、電子商取引のメッセージ標準である UBL を使用しています。 サンプルの電子インボイスを作成するためのツールをPythonで開発した。
以下は、次のGitHubで公開している genInvoice の解説。
https://github.com/pontsoleil/EIPA/tree/master/pint_ja
Pythonでは、XML文書を作成するライブラリ、xml.etree.ElementTreeを使用。
Excelで電子インボイスのデータを作成し、TSV形式(タブ区切り)で出力したファイルから、UBLの電子インボイスを作成する。
標準ではShift JIS出力されてしまい、ElementTreeでエラーとなるので、一旦テキストエディターで開いて、UTF-8に変換登録したものを入力ファイルとする。
TSVからUBLの電子インボイスを作成するプログラム genInvoice 及びUBLの電子インボイスをTSVに変換するプログラム invoice2tsv を作成した。

サンプル電子インボイス

CEFが公開している電子インボイスのGitHubからのサンプル電子インボイスを使用して検証します。

<?xml version="1.0" encoding="UTF-8"?>
<!--

    Licensed under European Union Public Licence (EUPL) version 1.2.

-->
<Invoice  xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
 xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
 xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDataTypes-2"
 xmlns:udt="urn:oasis:names:specification:ubl:schema:xsd:UnqualifiedDataTypes-2"
 xmlns:ccts="urn:un:unece:uncefact:documentation:2"
 xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2 http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd"> 
    <cbc:CustomizationID>urn:cen.eu:en16931:2017</cbc:CustomizationID>
    <cbc:ID>TOSL110</cbc:ID>
    <cbc:IssueDate>2013-04-10</cbc:IssueDate>
    <cbc:DueDate>2013-05-10</cbc:DueDate>
    <cbc:InvoiceTypeCode>380</cbc:InvoiceTypeCode>
    <cbc:DocumentCurrencyCode>DKK</cbc:DocumentCurrencyCode>
    <cac:AccountingSupplierParty>
        <cac:Party>
            <cac:PostalAddress>
                <cac:Country>
                    <cbc:IdentificationCode>DK</cbc:IdentificationCode>
                </cac:Country>
            </cac:PostalAddress>
            <cac:PartyTaxScheme>
                <cbc:CompanyID>DK123456789MVA</cbc:CompanyID>
                <cac:TaxScheme>
                    <cbc:ID>VAT</cbc:ID>
                </cac:TaxScheme>
            </cac:PartyTaxScheme>
            <cac:PartyLegalEntity>
                <cbc:RegistrationName>SellerCompany</cbc:RegistrationName>
            </cac:PartyLegalEntity>
        </cac:Party>
    </cac:AccountingSupplierParty>
    <cac:AccountingCustomerParty>
        <cac:Party>
            <cac:PostalAddress>
                <cac:Country>
                    <cbc:IdentificationCode>DK</cbc:IdentificationCode>
                </cac:Country>
            </cac:PostalAddress>
            <cac:PartyLegalEntity>
                <cbc:RegistrationName>Buyercompany ltd</cbc:RegistrationName>
            </cac:PartyLegalEntity>
        </cac:Party>
   </cac:AccountingCustomerParty>
    <cac:TaxTotal>
        <cbc:TaxAmount currencyID="DKK">675.00</cbc:TaxAmount>
        <cac:TaxSubtotal>
            <cbc:TaxableAmount currencyID="DKK">1500.00</cbc:TaxableAmount>
            <cbc:TaxAmount currencyID="DKK">375.00</cbc:TaxAmount>
            <cac:TaxCategory>
                <cbc:ID>S</cbc:ID>
                <cbc:Percent>25</cbc:Percent>
                <cac:TaxScheme>
                    <cbc:ID>VAT</cbc:ID>
                </cac:TaxScheme>
            </cac:TaxCategory>
        </cac:TaxSubtotal>
        <cac:TaxSubtotal>
            <cbc:TaxableAmount currencyID="DKK">2500.00</cbc:TaxableAmount>
            <cbc:TaxAmount currencyID="DKK">300.00</cbc:TaxAmount>
            <cac:TaxCategory>
                <cbc:ID>S</cbc:ID>
                <cbc:Percent>12</cbc:Percent>
                <cac:TaxScheme>
                    <cbc:ID>VAT</cbc:ID>
                </cac:TaxScheme>
            </cac:TaxCategory>
        </cac:TaxSubtotal>
    </cac:TaxTotal>
    <cac:LegalMonetaryTotal>
        <cbc:LineExtensionAmount currencyID="DKK">4000.00</cbc:LineExtensionAmount>
        <cbc:TaxExclusiveAmount currencyID="DKK">4000.00</cbc:TaxExclusiveAmount>
        <cbc:TaxInclusiveAmount currencyID="DKK">4675.00</cbc:TaxInclusiveAmount>
        <cbc:PayableAmount currencyID="DKK">4675.00</cbc:PayableAmount>
    </cac:LegalMonetaryTotal>
    <cac:InvoiceLine>
        <cbc:ID>1</cbc:ID>
        <cbc:InvoicedQuantity unitCode="EA">1000</cbc:InvoicedQuantity>
        <cbc:LineExtensionAmount currencyID="DKK">1000.00</cbc:LineExtensionAmount>
        <cac:Item>
            <cbc:Name>Printing paper</cbc:Name>
            <cac:ClassifiedTaxCategory>
                <cbc:ID>S</cbc:ID>
                <cbc:Percent>25</cbc:Percent>
                <cac:TaxScheme>
                    <cbc:ID>VAT</cbc:ID>
                </cac:TaxScheme>
            </cac:ClassifiedTaxCategory>
        </cac:Item>
        <cac:Price>
            <cbc:PriceAmount currencyID="DKK">1.00</cbc:PriceAmount>
        </cac:Price>
    </cac:InvoiceLine>
    <cac:InvoiceLine>
        <cbc:ID>2</cbc:ID>
        <cbc:InvoicedQuantity unitCode="EA">100</cbc:InvoicedQuantity>
        <cbc:LineExtensionAmount currencyID="DKK">500.00</cbc:LineExtensionAmount>
        <cac:Item>
            <cbc:Name>Parker Pen</cbc:Name>
            <cac:ClassifiedTaxCategory>
                <cbc:ID>S</cbc:ID>
                <cbc:Percent>25</cbc:Percent>
                <cac:TaxScheme>
                    <cbc:ID>VAT</cbc:ID>
                </cac:TaxScheme>
            </cac:ClassifiedTaxCategory>
        </cac:Item>
        <cac:Price>
            <cbc:PriceAmount currencyID="DKK">5.00</cbc:PriceAmount>
        </cac:Price>
    </cac:InvoiceLine>
    <cac:InvoiceLine>
        <cbc:ID>3</cbc:ID>
        <cbc:InvoicedQuantity unitCode="EA">500</cbc:InvoicedQuantity>
        <cbc:LineExtensionAmount currencyID="DKK">2500.00</cbc:LineExtensionAmount>
        <cac:Item>
            <cbc:Name>American Cookies</cbc:Name>
            <cac:ClassifiedTaxCategory>
                <cbc:ID>S</cbc:ID>
                <cbc:Percent>12</cbc:Percent>
                <cac:TaxScheme>
                    <cbc:ID>VAT</cbc:ID>
                </cac:TaxScheme>
            </cac:ClassifiedTaxCategory>
        </cac:Item>
        <cac:Price>
            <cbc:PriceAmount currencyID="DKK">5.00</cbc:PriceAmount>
        </cac:Price>
    </cac:InvoiceLine>
</Invoice>

ElementTreeのfromstring()で読み込み、tostring()で出力

Pythonプログラム

print(ET.tostring(root).decode()) で出力すると名前空間のコードがcac:からns3:等に変わってしまう。

import xml.etree.ElementTree as ET

root = ET.fromstring('''
  <Invoice  xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2"
  xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"
  xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDataTypes-2"
  xmlns:udt="urn:oasis:names:specification:ubl:schema:xsd:UnqualifiedDataTypes-2"
  xmlns:ccts="urn:un:unece:uncefact:documentation:2"
  xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2 http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd"> 
      <cbc:CustomizationID>urn:cen.eu:en16931:2017</cbc:CustomizationID>
      <cbc:ID>1100512149</cbc:ID>
      <cbc:IssueDate>2014-11-10</cbc:IssueDate>
      <cbc:DueDate>2014-11-24</cbc:DueDate>
      <cbc:InvoiceTypeCode>380</cbc:InvoiceTypeCode>
      <cbc:Note>Periodieke afrekening
          U vindt een toelichting op uw factuur via www.enexis.nl/factuur_grootzakelijk
          Op alle diensten en overeenkomsten zijn de algemene voorwaarden aansluiting en
          transport grootverbruik elektriciteit, respectievelijk gas van toepassing
          www.enexis.nl</cbc:Note>
      <cbc:TaxPointDate>2013-06-30</cbc:TaxPointDate>
      <cbc:DocumentCurrencyCode>EUR</cbc:DocumentCurrencyCode>
      <cac:InvoicePeriod>
          <cbc:StartDate>2014-08-01</cbc:StartDate>
          <cbc:EndDate>2014-08-31</cbc:EndDate>
      </cac:InvoicePeriod>
      <cac:AdditionalDocumentReference>
          <cbc:ID>871694831000290806</cbc:ID>
          <cbc:DocumentDescription>ATS</cbc:DocumentDescription>
      </cac:AdditionalDocumentReference>
      <cac:AccountingSupplierParty>
          <cac:Party>
              <cac:PartyName>
                  <cbc:Name>Enexis</cbc:Name>
              </cac:PartyName>
              <cac:PostalAddress>
                  <cbc:StreetName>Magistratenlaan 116</cbc:StreetName>
                  <cbc:CityName>'S-HERTOGENBOSCH</cbc:CityName>
                  <cbc:PostalZone>5223MB</cbc:PostalZone>
                  <cac:Country>
                      <cbc:IdentificationCode>NL</cbc:IdentificationCode>
                  </cac:Country>
              </cac:PostalAddress>
              <cac:PartyTaxScheme>
                  <cbc:CompanyID>NL809561074B01</cbc:CompanyID>
                  <cac:TaxScheme>
                      <cbc:ID>VAT</cbc:ID>
                  </cac:TaxScheme>
              </cac:PartyTaxScheme>
              <cac:PartyLegalEntity>
                  <cbc:RegistrationName>Enexis B.V.</cbc:RegistrationName>
                  <cbc:CompanyID>17131139</cbc:CompanyID>
              </cac:PartyLegalEntity>
              <cac:Contact>
                  <cbc:ElectronicMail>klantenservice.zakelijk@enexis.nl</cbc:ElectronicMail>
              </cac:Contact>
          </cac:Party>
      </cac:AccountingSupplierParty>
      <cac:AccountingCustomerParty>
          <cac:Party>
              <cac:PartyIdentification>
                  <cbc:ID>1081119</cbc:ID>
              </cac:PartyIdentification>
              <cac:PostalAddress>
                  <cbc:StreetName>Bedrijfslaan 4</cbc:StreetName>
                  <cbc:CityName>ONDERNEMERSTAD</cbc:CityName>
                  <cbc:PostalZone>9999 XX</cbc:PostalZone>
                  <cac:Country>
                      <cbc:IdentificationCode>NL</cbc:IdentificationCode>
                  </cac:Country>
              </cac:PostalAddress>
              <cac:PartyLegalEntity>
                  <cbc:RegistrationName>Klant</cbc:RegistrationName>
              </cac:PartyLegalEntity>
          </cac:Party>
    </cac:AccountingCustomerParty>
      <cac:Delivery>
          <cac:DeliveryLocation>
              <cac:Address>
                  <cbc:StreetName>Bedrijfslaan 4,</cbc:StreetName>
                  <cbc:CityName>ONDERNEMERSTAD</cbc:CityName>
                  <cbc:PostalZone>9999 XX</cbc:PostalZone>
                  <cac:Country>
                      <cbc:IdentificationCode>NL</cbc:IdentificationCode>
                  </cac:Country>
              </cac:Address>
          </cac:DeliveryLocation>
      </cac:Delivery>
      <cac:PaymentMeans>
          <cbc:PaymentMeansCode>30</cbc:PaymentMeansCode>
          <cbc:PaymentID>1100512149</cbc:PaymentID>
          <cac:PayeeFinancialAccount>
              <cbc:ID>NL28RBOS0420242228</cbc:ID>
          </cac:PayeeFinancialAccount>
      </cac:PaymentMeans>
      <cac:PaymentTerms>
          <cbc:Note>Enexis brengt wettelijke rente in rekening over te laat betaalde
              facturen. Kijk voor informatie op www.enexis.nl/rentenota</cbc:Note>        
      </cac:PaymentTerms>
      <cac:TaxTotal>
          <cbc:TaxAmount currencyID="EUR">190.87</cbc:TaxAmount>
          <cac:TaxSubtotal>
              <cbc:TaxableAmount currencyID="EUR">908.91</cbc:TaxableAmount>
              <cbc:TaxAmount currencyID="EUR">190.87</cbc:TaxAmount>
              <cac:TaxCategory>
                  <cbc:ID>S</cbc:ID>
                  <cbc:Percent>21</cbc:Percent>
                  <cac:TaxScheme>
                      <cbc:ID>VAT</cbc:ID>
                  </cac:TaxScheme>
              </cac:TaxCategory>
          </cac:TaxSubtotal>
      </cac:TaxTotal>
      <cac:LegalMonetaryTotal>
          <cbc:LineExtensionAmount currencyID="EUR">908.91</cbc:LineExtensionAmount>
          <cbc:TaxExclusiveAmount currencyID="EUR">908.91</cbc:TaxExclusiveAmount>
          <cbc:TaxInclusiveAmount currencyID="EUR">1099.78</cbc:TaxInclusiveAmount>
          <cbc:PayableAmount currencyID="EUR">1099.78</cbc:PayableAmount>
      </cac:LegalMonetaryTotal>
      <cac:InvoiceLine>
          <cbc:ID>1</cbc:ID>
          <cbc:InvoicedQuantity unitCode="KWH">16000</cbc:InvoicedQuantity>
          <cbc:LineExtensionAmount currencyID="EUR">140.80</cbc:LineExtensionAmount>
          <cac:Item>
              <cbc:Name>Getransporteerde kWh’s</cbc:Name>
              <cac:ClassifiedTaxCategory>
                  <cbc:ID>S</cbc:ID>
                  <cbc:Percent>21</cbc:Percent>
                  <cac:TaxScheme>
                      <cbc:ID>VAT</cbc:ID>
                  </cac:TaxScheme>
              </cac:ClassifiedTaxCategory>
              <cac:AdditionalItemProperty>
                  <cbc:Name>contract transportvermogen</cbc:Name>
                  <cbc:Value>132,00 kW</cbc:Value>
              </cac:AdditionalItemProperty>
              <cac:AdditionalItemProperty>
                  <cbc:Name>transporttarief</cbc:Name>
                  <cbc:Value>Netvlak MSD Enexis</cbc:Value>
              </cac:AdditionalItemProperty>
              <cac:AdditionalItemProperty>
                  <cbc:Name>netvlak</cbc:Name>
                  <cbc:Value>MS-D</cbc:Value>
              </cac:AdditionalItemProperty>
              <cac:AdditionalItemProperty>
                  <cbc:Name>correctiefactor</cbc:Name>
                  <cbc:Value>1,0130</cbc:Value>
              </cac:AdditionalItemProperty>
          </cac:Item>
          <cac:Price>
              <cbc:PriceAmount currencyID="EUR">0.00880</cbc:PriceAmount>
              <cbc:BaseQuantity unitCode="KWH">1</cbc:BaseQuantity>
          </cac:Price>
      </cac:InvoiceLine>
      <cac:InvoiceLine>
          <cbc:ID>2</cbc:ID>
          <cbc:InvoicedQuantity unitCode="KWH">16000</cbc:InvoicedQuantity>
          <cbc:LineExtensionAmount currencyID="EUR">16.16</cbc:LineExtensionAmount>
          <cac:Item>
              <cbc:Name>Systeemdiensten</cbc:Name>
              <cac:ClassifiedTaxCategory>
                  <cbc:ID>S</cbc:ID>
                  <cbc:Percent>21</cbc:Percent>
                  <cac:TaxScheme>
                      <cbc:ID>VAT</cbc:ID>
                  </cac:TaxScheme>
              </cac:ClassifiedTaxCategory>
              <cac:AdditionalItemProperty>
                  <cbc:Name>contract transportvermogen</cbc:Name>
                  <cbc:Value>132,00 kW</cbc:Value>
              </cac:AdditionalItemProperty>
              <cac:AdditionalItemProperty>
                  <cbc:Name>transporttarief</cbc:Name>
                  <cbc:Value>Netvlak MSD Enexis</cbc:Value>
              </cac:AdditionalItemProperty>
              <cac:AdditionalItemProperty>
                  <cbc:Name>netvlak</cbc:Name>
                  <cbc:Value>MS-D</cbc:Value>
              </cac:AdditionalItemProperty>
              <cac:AdditionalItemProperty>
                  <cbc:Name>correctiefactor</cbc:Name>
                  <cbc:Value>1,0130</cbc:Value>
              </cac:AdditionalItemProperty>
          </cac:Item>
          <cac:Price>
              <cbc:PriceAmount currencyID="EUR">0.00101</cbc:PriceAmount>
              <cbc:BaseQuantity unitCode="KWH">1</cbc:BaseQuantity>
          </cac:Price>
      </cac:InvoiceLine>
      <cac:InvoiceLine>
          <cbc:ID>3</cbc:ID>
          <cbc:InvoicedQuantity unitCode="KW">132</cbc:InvoicedQuantity>
          <cbc:LineExtensionAmount currencyID="EUR">167.64</cbc:LineExtensionAmount>
          <cac:Item>
              <cbc:Name>Contract transportvermogen</cbc:Name>
              <cac:ClassifiedTaxCategory>
                  <cbc:ID>S</cbc:ID>
                  <cbc:Percent>21</cbc:Percent>
                  <cac:TaxScheme>
                      <cbc:ID>VAT</cbc:ID>
                  </cac:TaxScheme>
              </cac:ClassifiedTaxCategory>
              <cac:AdditionalItemProperty>
                  <cbc:Name>contract transportvermogen</cbc:Name>
                  <cbc:Value>132,00 kW</cbc:Value>
              </cac:AdditionalItemProperty>
              <cac:AdditionalItemProperty>
                  <cbc:Name>transporttarief</cbc:Name>
                  <cbc:Value>Netvlak MSD Enexis</cbc:Value>
              </cac:AdditionalItemProperty>
              <cac:AdditionalItemProperty>
                  <cbc:Name>netvlak</cbc:Name>
                  <cbc:Value>MS-D</cbc:Value>
              </cac:AdditionalItemProperty>
              <cac:AdditionalItemProperty>
                  <cbc:Name>correctiefactor</cbc:Name>
                  <cbc:Value>1,0130</cbc:Value>
              </cac:AdditionalItemProperty>
          </cac:Item>
          <cac:Price>
              <cbc:PriceAmount currencyID="EUR">15.24</cbc:PriceAmount>
              <cbc:BaseQuantity unitCode="KW">12</cbc:BaseQuantity>
          </cac:Price>
      </cac:InvoiceLine>
      <cac:InvoiceLine>
          <cbc:ID>4</cbc:ID>
          <cbc:InvoicedQuantity unitCode="KW">58</cbc:InvoicedQuantity>
          <cbc:LineExtensionAmount currencyID="EUR">88.74</cbc:LineExtensionAmount>
          <cac:Item>
              <cbc:Name>Maximaal afgenomen vermogen</cbc:Name>
              <cac:ClassifiedTaxCategory>
                  <cbc:ID>S</cbc:ID>
                  <cbc:Percent>21</cbc:Percent>
                  <cac:TaxScheme>
                      <cbc:ID>VAT</cbc:ID>
                  </cac:TaxScheme>
              </cac:ClassifiedTaxCategory>
              <cac:AdditionalItemProperty>
                  <cbc:Name>contract transportvermogen</cbc:Name>
                  <cbc:Value>132,00 kW</cbc:Value>
              </cac:AdditionalItemProperty>
              <cac:AdditionalItemProperty>
                  <cbc:Name>transporttarief</cbc:Name>
                  <cbc:Value>Netvlak MSD Enexis</cbc:Value>
              </cac:AdditionalItemProperty>
              <cac:AdditionalItemProperty>
                  <cbc:Name>netvlak</cbc:Name>
                  <cbc:Value>MS-D</cbc:Value>
              </cac:AdditionalItemProperty>
              <cac:AdditionalItemProperty>
                  <cbc:Name>correctiefactor</cbc:Name>
                  <cbc:Value>1,0130</cbc:Value>
              </cac:AdditionalItemProperty>
          </cac:Item>
          <cac:Price>
              <cbc:PriceAmount currencyID="EUR">1.53</cbc:PriceAmount>
              <cbc:BaseQuantity unitCode="KW">1</cbc:BaseQuantity>
          </cac:Price>
      </cac:InvoiceLine>
      <cac:InvoiceLine>
          <cbc:ID>5</cbc:ID>
          <cbc:InvoicedQuantity unitCode="MON">1</cbc:InvoicedQuantity>
          <cbc:LineExtensionAmount currencyID="EUR">36.75</cbc:LineExtensionAmount>
          <cac:Item>
              <cbc:Name>Vastrecht Transportdienst</cbc:Name>
              <cac:ClassifiedTaxCategory>
                  <cbc:ID>S</cbc:ID>
                  <cbc:Percent>21</cbc:Percent>
                  <cac:TaxScheme>
                      <cbc:ID>VAT</cbc:ID>
                  </cac:TaxScheme>
              </cac:ClassifiedTaxCategory>
              <cac:AdditionalItemProperty>
                  <cbc:Name>contract transportvermogen</cbc:Name>
                  <cbc:Value>132,00 kW</cbc:Value>
              </cac:AdditionalItemProperty>
              <cac:AdditionalItemProperty>
                  <cbc:Name>transporttarief</cbc:Name>
                  <cbc:Value>Netvlak MSD Enexis</cbc:Value>
              </cac:AdditionalItemProperty>
              <cac:AdditionalItemProperty>
                  <cbc:Name>netvlak</cbc:Name>
                  <cbc:Value>MS-D</cbc:Value>
              </cac:AdditionalItemProperty>
              <cac:AdditionalItemProperty>
                  <cbc:Name>correctiefactor</cbc:Name>
                  <cbc:Value>1,0130</cbc:Value>
              </cac:AdditionalItemProperty>
          </cac:Item>
          <cac:Price>
              <cbc:PriceAmount currencyID="EUR">441.00</cbc:PriceAmount>
              <cbc:BaseQuantity unitCode="MON">12</cbc:BaseQuantity>
          </cac:Price>
      </cac:InvoiceLine>
      <cac:InvoiceLine>
          <cbc:ID>6</cbc:ID>
          <cbc:InvoicedQuantity unitCode="MON">1</cbc:InvoicedQuantity>
          <cbc:LineExtensionAmount currencyID="EUR">56.50</cbc:LineExtensionAmount>
          <cac:Item>
              <cbc:Name>Vastrecht Aansluitdienst</cbc:Name>
              <cac:ClassifiedTaxCategory>
                  <cbc:ID>S</cbc:ID>
                  <cbc:Percent>21</cbc:Percent>
                  <cac:TaxScheme>
                      <cbc:ID>VAT</cbc:ID>
                  </cac:TaxScheme>
              </cac:ClassifiedTaxCategory>
              <cac:AdditionalItemProperty>
                  <cbc:Name>contract transportvermogen</cbc:Name>
                  <cbc:Value>132,00 kW</cbc:Value>
              </cac:AdditionalItemProperty>
              <cac:AdditionalItemProperty>
                  <cbc:Name>transporttarief</cbc:Name>
                  <cbc:Value>Netvlak MSD Enexis</cbc:Value>
              </cac:AdditionalItemProperty>
              <cac:AdditionalItemProperty>
                  <cbc:Name>netvlak</cbc:Name>
                  <cbc:Value>MS-D</cbc:Value>
              </cac:AdditionalItemProperty>
              <cac:AdditionalItemProperty>
                  <cbc:Name>correctiefactor</cbc:Name>
                  <cbc:Value>1,0130</cbc:Value>
              </cac:AdditionalItemProperty>
          </cac:Item>
          <cac:Price>
              <cbc:PriceAmount currencyID="EUR">678.00</cbc:PriceAmount>
              <cbc:BaseQuantity unitCode="MON">12</cbc:BaseQuantity>
          </cac:Price>
      </cac:InvoiceLine>
      <cac:InvoiceLine>
          <cbc:ID>7</cbc:ID>
          <cbc:InvoicedQuantity unitCode="MON">1</cbc:InvoicedQuantity>
          <cbc:LineExtensionAmount currencyID="EUR">83.34</cbc:LineExtensionAmount>
          <cac:Item>
              <cbc:Name>Huur Transformatoren</cbc:Name>
              <cac:ClassifiedTaxCategory>
                  <cbc:ID>S</cbc:ID>
                  <cbc:Percent>21</cbc:Percent>
                  <cac:TaxScheme>
                      <cbc:ID>VAT</cbc:ID>
                  </cac:TaxScheme>
              </cac:ClassifiedTaxCategory>
          </cac:Item>
          <cac:Price>
              <cbc:PriceAmount currencyID="EUR">83.34</cbc:PriceAmount>
              <cbc:BaseQuantity unitCode="MON">1</cbc:BaseQuantity>
          </cac:Price>
      </cac:InvoiceLine>
      <cac:InvoiceLine>
          <cbc:ID>8</cbc:ID>
          <cbc:InvoicedQuantity unitCode="MON">1</cbc:InvoicedQuantity>
          <cbc:LineExtensionAmount currencyID="EUR">190.31</cbc:LineExtensionAmount>
          <cac:Item>
              <cbc:Name>Huur Schakelinstallaties</cbc:Name>
              <cac:ClassifiedTaxCategory>
                  <cbc:ID>S</cbc:ID>
                  <cbc:Percent>21</cbc:Percent>
                  <cac:TaxScheme>
                      <cbc:ID>VAT</cbc:ID>
                  </cac:TaxScheme>
              </cac:ClassifiedTaxCategory>
          </cac:Item>
          <cac:Price>
              <cbc:PriceAmount currencyID="EUR">190.31</cbc:PriceAmount>
              <cbc:BaseQuantity unitCode="MON">1</cbc:BaseQuantity>
          </cac:Price>
      </cac:InvoiceLine>
      <cac:InvoiceLine>
          <cbc:ID>9</cbc:ID>
          <cbc:InvoicedQuantity unitCode="MON">1</cbc:InvoicedQuantity>
          <cbc:LineExtensionAmount currencyID="EUR">64.21</cbc:LineExtensionAmount>
          <cac:Item>
              <cbc:Name>Huur Overige Apparaten</cbc:Name>
              <cac:ClassifiedTaxCategory>
                  <cbc:ID>S</cbc:ID>
                  <cbc:Percent>21</cbc:Percent>
                  <cac:TaxScheme>
                      <cbc:ID>VAT</cbc:ID>
                  </cac:TaxScheme>
              </cac:ClassifiedTaxCategory>
          </cac:Item>
          <cac:Price>
              <cbc:PriceAmount currencyID="EUR">64.21</cbc:PriceAmount>
              <cbc:BaseQuantity unitCode="MON">1</cbc:BaseQuantity>
          </cac:Price>
      </cac:InvoiceLine>
      <cac:InvoiceLine>
          <cbc:ID>10</cbc:ID>
          <cbc:InvoicedQuantity unitCode="MON">1</cbc:InvoicedQuantity>
          <cbc:LineExtensionAmount currencyID="EUR">64.46</cbc:LineExtensionAmount>
          <cac:Item>
              <cbc:Name>Huur Meterdiensten</cbc:Name>
              <cac:ClassifiedTaxCategory>
                  <cbc:ID>S</cbc:ID>
                  <cbc:Percent>21</cbc:Percent>
                  <cac:TaxScheme>
                      <cbc:ID>VAT</cbc:ID>
                  </cac:TaxScheme>
              </cac:ClassifiedTaxCategory>
          </cac:Item>
          <cac:Price>
              <cbc:PriceAmount currencyID="EUR">64.46</cbc:PriceAmount>
              <cbc:BaseQuantity unitCode="MON">1</cbc:BaseQuantity>
          </cac:Price>
      </cac:InvoiceLine>
  </Invoice>
  ''')

print(ET.tostring(root).decode())

出力結果

<ns0:Invoice xmlns:ns0="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:ns2="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ns3="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2 http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd"> 
      <ns2:CustomizationID>urn:cen.eu:en16931:2017</ns2:CustomizationID>
      <ns2:ID>1100512149</ns2:ID>
      <ns2:IssueDate>2014-11-10</ns2:IssueDate>
      <ns2:DueDate>2014-11-24</ns2:DueDate>
      <ns2:InvoiceTypeCode>380</ns2:InvoiceTypeCode>
      <ns2:Note>Periodieke afrekening
          U vindt een toelichting op uw factuur via www.enexis.nl/factuur_grootzakelijk
          Op alle diensten en overeenkomsten zijn de algemene voorwaarden aansluiting en
          transport grootverbruik elektriciteit, respectievelijk gas van toepassing
          www.enexis.nl</ns2:Note>
      <ns2:TaxPointDate>2013-06-30</ns2:TaxPointDate>
      <ns2:DocumentCurrencyCode>EUR</ns2:DocumentCurrencyCode>
      <ns3:InvoicePeriod>
          <ns2:StartDate>2014-08-01</ns2:StartDate>
          <ns2:EndDate>2014-08-31</ns2:EndDate>
      </ns3:InvoicePeriod>
      <ns3:AdditionalDocumentReference>
          <ns2:ID>871694831000290806</ns2:ID>
          <ns2:DocumentDescription>ATS</ns2:DocumentDescription>
      </ns3:AdditionalDocumentReference>
      <ns3:AccountingSupplierParty>
          <ns3:Party>
              <ns3:PartyName>
                  <ns2:Name>Enexis</ns2:Name>
              </ns3:PartyName>
              <ns3:PostalAddress>
                  <ns2:StreetName>Magistratenlaan 116</ns2:StreetName>
                  <ns2:CityName>'S-HERTOGENBOSCH</ns2:CityName>
                  <ns2:PostalZone>5223MB</ns2:PostalZone>
                  <ns3:Country>
                      <ns2:IdentificationCode>NL</ns2:IdentificationCode>
                  </ns3:Country>
              </ns3:PostalAddress>
              <ns3:PartyTaxScheme>
                  <ns2:CompanyID>NL809561074B01</ns2:CompanyID>
                  <ns3:TaxScheme>
                      <ns2:ID>VAT</ns2:ID>
                  </ns3:TaxScheme>
              </ns3:PartyTaxScheme>
              <ns3:PartyLegalEntity>
                  <ns2:RegistrationName>Enexis B.V.</ns2:RegistrationName>
                  <ns2:CompanyID>17131139</ns2:CompanyID>
              </ns3:PartyLegalEntity>
              <ns3:Contact>
                  <ns2:ElectronicMail>klantenservice.zakelijk@enexis.nl</ns2:ElectronicMail>
              </ns3:Contact>
          </ns3:Party>
      </ns3:AccountingSupplierParty>
      <ns3:AccountingCustomerParty>
          <ns3:Party>
              <ns3:PartyIdentification>
                  <ns2:ID>1081119</ns2:ID>
              </ns3:PartyIdentification>
              <ns3:PostalAddress>
                  <ns2:StreetName>Bedrijfslaan 4</ns2:StreetName>
                  <ns2:CityName>ONDERNEMERSTAD</ns2:CityName>
                  <ns2:PostalZone>9999 XX</ns2:PostalZone>
                  <ns3:Country>
                      <ns2:IdentificationCode>NL</ns2:IdentificationCode>
                  </ns3:Country>
              </ns3:PostalAddress>
              <ns3:PartyLegalEntity>
                  <ns2:RegistrationName>Klant</ns2:RegistrationName>
              </ns3:PartyLegalEntity>
          </ns3:Party>
    </ns3:AccountingCustomerParty>
      <ns3:Delivery>
          <ns3:DeliveryLocation>
              <ns3:Address>
                  <ns2:StreetName>Bedrijfslaan 4,</ns2:StreetName>
                  <ns2:CityName>ONDERNEMERSTAD</ns2:CityName>
                  <ns2:PostalZone>9999 XX</ns2:PostalZone>
                  <ns3:Country>
                      <ns2:IdentificationCode>NL</ns2:IdentificationCode>
                  </ns3:Country>
              </ns3:Address>
          </ns3:DeliveryLocation>
      </ns3:Delivery>
      <ns3:PaymentMeans>
          <ns2:PaymentMeansCode>30</ns2:PaymentMeansCode>
          <ns2:PaymentID>1100512149</ns2:PaymentID>
          <ns3:PayeeFinancialAccount>
              <ns2:ID>NL28RBOS0420242228</ns2:ID>
          </ns3:PayeeFinancialAccount>
      </ns3:PaymentMeans>
      <ns3:PaymentTerms>
          <ns2:Note>Enexis brengt wettelijke rente in rekening over te laat betaalde
              facturen. Kijk voor informatie op www.enexis.nl/rentenota</ns2:Note>        
      </ns3:PaymentTerms>
      <ns3:TaxTotal>
          <ns2:TaxAmount currencyID="EUR">190.87</ns2:TaxAmount>
          <ns3:TaxSubtotal>
              <ns2:TaxableAmount currencyID="EUR">908.91</ns2:TaxableAmount>
              <ns2:TaxAmount currencyID="EUR">190.87</ns2:TaxAmount>
              <ns3:TaxCategory>
                  <ns2:ID>S</ns2:ID>
                  <ns2:Percent>21</ns2:Percent>
                  <ns3:TaxScheme>
                      <ns2:ID>VAT</ns2:ID>
                  </ns3:TaxScheme>
              </ns3:TaxCategory>
          </ns3:TaxSubtotal>
      </ns3:TaxTotal>
      <ns3:LegalMonetaryTotal>
          <ns2:LineExtensionAmount currencyID="EUR">908.91</ns2:LineExtensionAmount>
          <ns2:TaxExclusiveAmount currencyID="EUR">908.91</ns2:TaxExclusiveAmount>
          <ns2:TaxInclusiveAmount currencyID="EUR">1099.78</ns2:TaxInclusiveAmount>
          <ns2:PayableAmount currencyID="EUR">1099.78</ns2:PayableAmount>
      </ns3:LegalMonetaryTotal>
      <ns3:InvoiceLine>
          <ns2:ID>1</ns2:ID>
          <ns2:InvoicedQuantity unitCode="KWH">16000</ns2:InvoicedQuantity>
          <ns2:LineExtensionAmount currencyID="EUR">140.80</ns2:LineExtensionAmount>
          <ns3:Item>
              <ns2:Name>Getransporteerde kWh&#8217;s</ns2:Name>
              <ns3:ClassifiedTaxCategory>
                  <ns2:ID>S</ns2:ID>
                  <ns2:Percent>21</ns2:Percent>
                  <ns3:TaxScheme>
                      <ns2:ID>VAT</ns2:ID>
                  </ns3:TaxScheme>
              </ns3:ClassifiedTaxCategory>
              <ns3:AdditionalItemProperty>
                  <ns2:Name>contract transportvermogen</ns2:Name>
                  <ns2:Value>132,00 kW</ns2:Value>
              </ns3:AdditionalItemProperty>
              <ns3:AdditionalItemProperty>
                  <ns2:Name>transporttarief</ns2:Name>
                  <ns2:Value>Netvlak MSD Enexis</ns2:Value>
              </ns3:AdditionalItemProperty>
              <ns3:AdditionalItemProperty>
                  <ns2:Name>netvlak</ns2:Name>
                  <ns2:Value>MS-D</ns2:Value>
              </ns3:AdditionalItemProperty>
              <ns3:AdditionalItemProperty>
                  <ns2:Name>correctiefactor</ns2:Name>
                  <ns2:Value>1,0130</ns2:Value>
              </ns3:AdditionalItemProperty>
          </ns3:Item>
          <ns3:Price>
              <ns2:PriceAmount currencyID="EUR">0.00880</ns2:PriceAmount>
              <ns2:BaseQuantity unitCode="KWH">1</ns2:BaseQuantity>
          </ns3:Price>
      </ns3:InvoiceLine>
      <ns3:InvoiceLine>
          <ns2:ID>2</ns2:ID>
          <ns2:InvoicedQuantity unitCode="KWH">16000</ns2:InvoicedQuantity>
          <ns2:LineExtensionAmount currencyID="EUR">16.16</ns2:LineExtensionAmount>
          <ns3:Item>
              <ns2:Name>Systeemdiensten</ns2:Name>
              <ns3:ClassifiedTaxCategory>
                  <ns2:ID>S</ns2:ID>
                  <ns2:Percent>21</ns2:Percent>
                  <ns3:TaxScheme>
                      <ns2:ID>VAT</ns2:ID>
                  </ns3:TaxScheme>
              </ns3:ClassifiedTaxCategory>
              <ns3:AdditionalItemProperty>
                  <ns2:Name>contract transportvermogen</ns2:Name>
                  <ns2:Value>132,00 kW</ns2:Value>
              </ns3:AdditionalItemProperty>
              <ns3:AdditionalItemProperty>
                  <ns2:Name>transporttarief</ns2:Name>
                  <ns2:Value>Netvlak MSD Enexis</ns2:Value>
              </ns3:AdditionalItemProperty>
              <ns3:AdditionalItemProperty>
                  <ns2:Name>netvlak</ns2:Name>
                  <ns2:Value>MS-D</ns2:Value>
              </ns3:AdditionalItemProperty>
              <ns3:AdditionalItemProperty>
                  <ns2:Name>correctiefactor</ns2:Name>
                  <ns2:Value>1,0130</ns2:Value>
              </ns3:AdditionalItemProperty>
          </ns3:Item>
          <ns3:Price>
              <ns2:PriceAmount currencyID="EUR">0.00101</ns2:PriceAmount>
              <ns2:BaseQuantity unitCode="KWH">1</ns2:BaseQuantity>
          </ns3:Price>
      </ns3:InvoiceLine>
      <ns3:InvoiceLine>
          <ns2:ID>3</ns2:ID>
          <ns2:InvoicedQuantity unitCode="KW">132</ns2:InvoicedQuantity>
          <ns2:LineExtensionAmount currencyID="EUR">167.64</ns2:LineExtensionAmount>
          <ns3:Item>
              <ns2:Name>Contract transportvermogen</ns2:Name>
              <ns3:ClassifiedTaxCategory>
                  <ns2:ID>S</ns2:ID>
                  <ns2:Percent>21</ns2:Percent>
                  <ns3:TaxScheme>
                      <ns2:ID>VAT</ns2:ID>
                  </ns3:TaxScheme>
              </ns3:ClassifiedTaxCategory>
              <ns3:AdditionalItemProperty>
                  <ns2:Name>contract transportvermogen</ns2:Name>
                  <ns2:Value>132,00 kW</ns2:Value>
              </ns3:AdditionalItemProperty>
              <ns3:AdditionalItemProperty>
                  <ns2:Name>transporttarief</ns2:Name>
                  <ns2:Value>Netvlak MSD Enexis</ns2:Value>
              </ns3:AdditionalItemProperty>
              <ns3:AdditionalItemProperty>
                  <ns2:Name>netvlak</ns2:Name>
                  <ns2:Value>MS-D</ns2:Value>
              </ns3:AdditionalItemProperty>
              <ns3:AdditionalItemProperty>
                  <ns2:Name>correctiefactor</ns2:Name>
                  <ns2:Value>1,0130</ns2:Value>
              </ns3:AdditionalItemProperty>
          </ns3:Item>
          <ns3:Price>
              <ns2:PriceAmount currencyID="EUR">15.24</ns2:PriceAmount>
              <ns2:BaseQuantity unitCode="KW">12</ns2:BaseQuantity>
          </ns3:Price>
      </ns3:InvoiceLine>
      <ns3:InvoiceLine>
          <ns2:ID>4</ns2:ID>
          <ns2:InvoicedQuantity unitCode="KW">58</ns2:InvoicedQuantity>
          <ns2:LineExtensionAmount currencyID="EUR">88.74</ns2:LineExtensionAmount>
          <ns3:Item>
              <ns2:Name>Maximaal afgenomen vermogen</ns2:Name>
              <ns3:ClassifiedTaxCategory>
                  <ns2:ID>S</ns2:ID>
                  <ns2:Percent>21</ns2:Percent>
                  <ns3:TaxScheme>
                      <ns2:ID>VAT</ns2:ID>
                  </ns3:TaxScheme>
              </ns3:ClassifiedTaxCategory>
              <ns3:AdditionalItemProperty>
                  <ns2:Name>contract transportvermogen</ns2:Name>
                  <ns2:Value>132,00 kW</ns2:Value>
              </ns3:AdditionalItemProperty>
              <ns3:AdditionalItemProperty>
                  <ns2:Name>transporttarief</ns2:Name>
                  <ns2:Value>Netvlak MSD Enexis</ns2:Value>
              </ns3:AdditionalItemProperty>
              <ns3:AdditionalItemProperty>
                  <ns2:Name>netvlak</ns2:Name>
                  <ns2:Value>MS-D</ns2:Value>
              </ns3:AdditionalItemProperty>
              <ns3:AdditionalItemProperty>
                  <ns2:Name>correctiefactor</ns2:Name>
                  <ns2:Value>1,0130</ns2:Value>
              </ns3:AdditionalItemProperty>
          </ns3:Item>
          <ns3:Price>
              <ns2:PriceAmount currencyID="EUR">1.53</ns2:PriceAmount>
              <ns2:BaseQuantity unitCode="KW">1</ns2:BaseQuantity>
          </ns3:Price>
      </ns3:InvoiceLine>
      <ns3:InvoiceLine>
          <ns2:ID>5</ns2:ID>
          <ns2:InvoicedQuantity unitCode="MON">1</ns2:InvoicedQuantity>
          <ns2:LineExtensionAmount currencyID="EUR">36.75</ns2:LineExtensionAmount>
          <ns3:Item>
              <ns2:Name>Vastrecht Transportdienst</ns2:Name>
              <ns3:ClassifiedTaxCategory>
                  <ns2:ID>S</ns2:ID>
                  <ns2:Percent>21</ns2:Percent>
                  <ns3:TaxScheme>
                      <ns2:ID>VAT</ns2:ID>
                  </ns3:TaxScheme>
              </ns3:ClassifiedTaxCategory>
              <ns3:AdditionalItemProperty>
                  <ns2:Name>contract transportvermogen</ns2:Name>
                  <ns2:Value>132,00 kW</ns2:Value>
              </ns3:AdditionalItemProperty>
              <ns3:AdditionalItemProperty>
                  <ns2:Name>transporttarief</ns2:Name>
                  <ns2:Value>Netvlak MSD Enexis</ns2:Value>
              </ns3:AdditionalItemProperty>
              <ns3:AdditionalItemProperty>
                  <ns2:Name>netvlak</ns2:Name>
                  <ns2:Value>MS-D</ns2:Value>
              </ns3:AdditionalItemProperty>
              <ns3:AdditionalItemProperty>
                  <ns2:Name>correctiefactor</ns2:Name>
                  <ns2:Value>1,0130</ns2:Value>
              </ns3:AdditionalItemProperty>
          </ns3:Item>
          <ns3:Price>
              <ns2:PriceAmount currencyID="EUR">441.00</ns2:PriceAmount>
              <ns2:BaseQuantity unitCode="MON">12</ns2:BaseQuantity>
          </ns3:Price>
      </ns3:InvoiceLine>
      <ns3:InvoiceLine>
          <ns2:ID>6</ns2:ID>
          <ns2:InvoicedQuantity unitCode="MON">1</ns2:InvoicedQuantity>
          <ns2:LineExtensionAmount currencyID="EUR">56.50</ns2:LineExtensionAmount>
          <ns3:Item>
              <ns2:Name>Vastrecht Aansluitdienst</ns2:Name>
              <ns3:ClassifiedTaxCategory>
                  <ns2:ID>S</ns2:ID>
                  <ns2:Percent>21</ns2:Percent>
                  <ns3:TaxScheme>
                      <ns2:ID>VAT</ns2:ID>
                  </ns3:TaxScheme>
              </ns3:ClassifiedTaxCategory>
              <ns3:AdditionalItemProperty>
                  <ns2:Name>contract transportvermogen</ns2:Name>
                  <ns2:Value>132,00 kW</ns2:Value>
              </ns3:AdditionalItemProperty>
              <ns3:AdditionalItemProperty>
                  <ns2:Name>transporttarief</ns2:Name>
                  <ns2:Value>Netvlak MSD Enexis</ns2:Value>
              </ns3:AdditionalItemProperty>
              <ns3:AdditionalItemProperty>
                  <ns2:Name>netvlak</ns2:Name>
                  <ns2:Value>MS-D</ns2:Value>
              </ns3:AdditionalItemProperty>
              <ns3:AdditionalItemProperty>
                  <ns2:Name>correctiefactor</ns2:Name>
                  <ns2:Value>1,0130</ns2:Value>
              </ns3:AdditionalItemProperty>
          </ns3:Item>
          <ns3:Price>
              <ns2:PriceAmount currencyID="EUR">678.00</ns2:PriceAmount>
              <ns2:BaseQuantity unitCode="MON">12</ns2:BaseQuantity>
          </ns3:Price>
      </ns3:InvoiceLine>
      <ns3:InvoiceLine>
          <ns2:ID>7</ns2:ID>
          <ns2:InvoicedQuantity unitCode="MON">1</ns2:InvoicedQuantity>
          <ns2:LineExtensionAmount currencyID="EUR">83.34</ns2:LineExtensionAmount>
          <ns3:Item>
              <ns2:Name>Huur Transformatoren</ns2:Name>
              <ns3:ClassifiedTaxCategory>
                  <ns2:ID>S</ns2:ID>
                  <ns2:Percent>21</ns2:Percent>
                  <ns3:TaxScheme>
                      <ns2:ID>VAT</ns2:ID>
                  </ns3:TaxScheme>
              </ns3:ClassifiedTaxCategory>
          </ns3:Item>
          <ns3:Price>
              <ns2:PriceAmount currencyID="EUR">83.34</ns2:PriceAmount>
              <ns2:BaseQuantity unitCode="MON">1</ns2:BaseQuantity>
          </ns3:Price>
      </ns3:InvoiceLine>
      <ns3:InvoiceLine>
          <ns2:ID>8</ns2:ID>
          <ns2:InvoicedQuantity unitCode="MON">1</ns2:InvoicedQuantity>
          <ns2:LineExtensionAmount currencyID="EUR">190.31</ns2:LineExtensionAmount>
          <ns3:Item>
              <ns2:Name>Huur Schakelinstallaties</ns2:Name>
              <ns3:ClassifiedTaxCategory>
                  <ns2:ID>S</ns2:ID>
                  <ns2:Percent>21</ns2:Percent>
                  <ns3:TaxScheme>
                      <ns2:ID>VAT</ns2:ID>
                  </ns3:TaxScheme>
              </ns3:ClassifiedTaxCategory>
          </ns3:Item>
          <ns3:Price>
              <ns2:PriceAmount currencyID="EUR">190.31</ns2:PriceAmount>
              <ns2:BaseQuantity unitCode="MON">1</ns2:BaseQuantity>
          </ns3:Price>
      </ns3:InvoiceLine>
      <ns3:InvoiceLine>
          <ns2:ID>9</ns2:ID>
          <ns2:InvoicedQuantity unitCode="MON">1</ns2:InvoicedQuantity>
          <ns2:LineExtensionAmount currencyID="EUR">64.21</ns2:LineExtensionAmount>
          <ns3:Item>
              <ns2:Name>Huur Overige Apparaten</ns2:Name>
              <ns3:ClassifiedTaxCategory>
                  <ns2:ID>S</ns2:ID>
                  <ns2:Percent>21</ns2:Percent>
                  <ns3:TaxScheme>
                      <ns2:ID>VAT</ns2:ID>
                  </ns3:TaxScheme>
              </ns3:ClassifiedTaxCategory>
          </ns3:Item>
          <ns3:Price>
              <ns2:PriceAmount currencyID="EUR">64.21</ns2:PriceAmount>
              <ns2:BaseQuantity unitCode="MON">1</ns2:BaseQuantity>
          </ns3:Price>
      </ns3:InvoiceLine>
      <ns3:InvoiceLine>
          <ns2:ID>10</ns2:ID>
          <ns2:InvoicedQuantity unitCode="MON">1</ns2:InvoicedQuantity>
          <ns2:LineExtensionAmount currencyID="EUR">64.46</ns2:LineExtensionAmount>
          <ns3:Item>
              <ns2:Name>Huur Meterdiensten</ns2:Name>
              <ns3:ClassifiedTaxCategory>
                  <ns2:ID>S</ns2:ID>
                  <ns2:Percent>21</ns2:Percent>
                  <ns3:TaxScheme>
                      <ns2:ID>VAT</ns2:ID>
                  </ns3:TaxScheme>
              </ns3:ClassifiedTaxCategory>
          </ns3:Item>
          <ns3:Price>
              <ns2:PriceAmount currencyID="EUR">64.46</ns2:PriceAmount>
              <ns2:BaseQuantity unitCode="MON">1</ns2:BaseQuantity>
          </ns3:Price>
      </ns3:InvoiceLine>
  </ns0:Invoice>

名前空間の記号を登録

ET.register_namespace(‘cbc’, ‘urn:…’) のように名前空間を登録することと xsi:schemaLocation の記載のあるをあらかじめ読み込んでおきそれに要素や属性を追加することで対策した。

ET.register_namespace('cac', 'urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2')
ET.register_namespace('cbc', 'urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2')
ET.register_namespace('qdt', 'urn:oasis:names:specification:ubl:schema:xsd:QualifiedDataTypes-2')
ET.register_namespace('udt', 'urn:oasis:names:specification:ubl:schema:xsd:UnqualifiedDataTypes-2')
ET.register_namespace('ccts', 'urn:un:unece:uncefact:documentation:2')
ET.register_namespace('', 'urn:oasis:names:specification:ubl:schema:xsd:Invoice-2')

root = ET.XML('''
    <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" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:schemaLocation="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2 http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-Invoice-2.1.xsd" /> 
    ''')  # this step adds xsi:schemaLocation attribute
tree = dict_to_etree(dic2, root)

with open(out_file, 'wb') as f:
  t = ET.ElementTree(tree)
  t.write(f, encoding='UTF-8')


投稿日

カテゴリー:

投稿者:

タグ: