Dear all,
Good day.
I am building an xml file using lxml on Odoo12.
On the final result, I get all data on the same lines, like:
<AuditFile xmlns="urn:OECD:StandardAuditFile-Tax:PT_1.01_01"><Header xmlns="urn:OECD:StandardAuditFile-Tax:PT_1.01_01"><AuditFileVersion>1.01_01</AuditFileVersion><CompanyID>REG102.2548</CompanyID><TaxRegistrationNumber>1234567890</TaxRegistrationNumber><TaxAccountingBasis>F</TaxAccountingBasis><CompanyName>My Company</CompanyName><BusinessName> </BusinessName><CompanyAddress><BuildingNumber> </BuildingNumber><StreetName>Endreço da empresa</StreetName><City>Setubal</City><PostalCode> </PostalCode><Country>PT</Country></CompanyAddress>
<FiscalYear>2019</FiscalYear><StartDate>2019-10-20</StartDate><EndDate>2019-10-20</EndDate><CurrencyCode>PT</CurrencyCode><DateCreated>2019-10-20</DateCreated><TaxEntity>Global</TaxEntity><ProductCompanyTaxID>507477758</ProductCompanyTaxID><SoftwareValidationNumber>0</SoftwareValidationNumber><ProductID>Odoo</ProductID><ProductVersion>12</ProductVersion><HeaderComment>Odoo - OpenSource #1</HeaderComment><Telephone> </Telephone><Fax> </Fax><Email>info@yourcompany.com</Email><Website>http://www.yourcompany.com</Website></Header>
</AuditFile>
How can I get the results on a more clear and readable format with an element per line, like:
<AuditFile xmlns="urn:OECD:StandardAuditFile-Tax:PT_1.01_01">
<Header xmlns="urn:OECD:StandardAuditFile-Tax:PT_1.01_01">
<AuditFileVersion>1.01_01</AuditFileVersion>
<CompanyID>REG102.2548</CompanyID>
<TaxRegistrationNumber>1234567890</TaxRegistrationNumber>
<BusinessName> </BusinessName>
<CompanyAddress>
<BuildingNumber> </BuildingNumber>
<PostalCode> </PostalCode>
<Country>PT</Country>
</CompanyAddress>
<FiscalYear>2019</FiscalYear>
<TaxEntity>Global</TaxEntity>
<ProductCompanyTaxID>507477758</ProductCompanyTaxID>
<SoftwareValidationNumber>0</SoftwareValidationNumber>
<ProductID>Odoo</ProductID>
</Header>
</AuditFile>
The code I am using for writing the xml is something like:
#For the root and header element
root = et.Element("AuditFile", attrib = attrib)
header = et.SubElement(root, 'Header', xmlns=self.xmlns)
header.tail = '\n'
#For the SubElement AuditFileVersion
et.SubElement(header, 'AuditFileVersion').text='1.01_01'
#HEADER
header_block = (
('CompanyID', CompanyID),
('TaxRegistrationNumber', TaxRegistrationNumber),
('TaxAccountingBasis', TaxAccountingBasis),
('CompanyName', CompanyName),
('BusinessName', BusinessName),
)
for tag, value in header_block:
if value is None :
continue
et.SubElement(header, tag).text= value
#Header | CompanyAddress
headerCompanyAddress = et.SubElement(header, 'CompanyAddress')
headerCompanyAddress.tail = '\n'
header_block = (
('BuildingNumber', BuildingNumber),
('StreetName', StreetName),
('AddressDetail', AddressDetail),
('City', City),
('PostalCode', PostalCode),
('Province', Province),
('Country', 'AO'),
)
for tag, value in header_block:
if value is None :
continue
et.SubElement(headerCompanyAddress, tag).text= value
...and so on!
Thank you all in advance
Best regards
PM
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
3387
Lượt xem
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
2
thg 5 25
|
7864 | ||
|
2
thg 12 19
|
5072 | ||
|
1
thg 7 19
|
6370 | ||
|
0
thg 10 18
|
4082 | ||
|
1
thg 9 22
|
7540 |