Описание сервисов, скрипт
Скрипт-код для парсинга инфы с xsd. файлов, который после преобразовывает в таблицы docx.unknown
plain_text
3 years ago
2.1 kB
11
Indexable
import os
import xml.etree.ElementTree as ET
import docx
from docx.shared import Pt
def parse_to_file(xml_text, file_name):
root = ET.fromstring(xml_text)
doc = docx.Document()
style = doc.styles['Normal']
font = style.font
font.name = 'Times New Roman'
table = doc.add_table(rows=1, cols=3)
table.style = 'Table Grid'
header_cells = table.rows[0].cells
header_cells[0].text = "Поле"
header_cells[1].text = "Тип"
header_cells[2].text = "Документация"
result = {}
for elem in root.findall('.//{http://www.w3.org/2001/XMLSchema}element'):
name = elem.get('name')
_type = elem.get('type')
if _type is not None:
_type = _type.replace("xsd:", "")
if elem.find('.//{http://www.w3.org/2001/XMLSchema}documentation') is None:
continue
documentation = elem.find('.//{http://www.w3.org/2001/XMLSchema}documentation').text.strip()
result[name] = (_type, documentation)
for name, (_type, documentation) in result.items():
row_cells = table.add_row().cells
if name is None:
name = ""
if _type is None:
_type = ""
if documentation is None:
documentation = ""
row_cells[0].text = name
row_cells[1].text = _type
row_cells[2].text = documentation
doc.save(file_name)
if __name__ == '__main__':
#вставляем сюда нужный path
path = "C:\\Users\\trrra\\Desktop\\AIS-SC2-services\\AisLimitSoapService\\sync\\Arrest\\MIA_AISSC_REMOVE_ARREST_LIMIT\\xsd"
dir_list = os.listdir(path)
print("Files and directories in '", path, "' :")
for xsd_file in dir_list:
if xsd_file.endswith("xsd"):
with open(path + "\\" + xsd_file, 'r', encoding='utf-8') as file:
data = file.read()
docx_name = xsd_file.replace("xsd", "docx")
parse_to_file(data, path + "\\" + docx_name)Editor is loading...