-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror_list.py
More file actions
73 lines (53 loc) · 2.35 KB
/
error_list.py
File metadata and controls
73 lines (53 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import csv
from xml.dom.minidom import Document, DOMImplementation
def prepare_xml(csv_data):
imp = DOMImplementation()
doctype = imp.createDocumentType("concept", "-//OASIS//DTD DITA Concept//EN", "concept.dtd")
doc = Document()
doc.appendChild(doctype)
concept = doc.createElement("concept")
concept.setAttribute("base", "pdm-category(Platforms) pdm-subcategory(Platform Products) pdm-product(DX 200 SW Platform) keys(ref_errormsg)")
concept.setAttribute("id", "error_list")
title = doc.createElement("title")
title_text = doc.createTextNode("Error messages list")
title.appendChild(title_text)
concept.appendChild(title)
shortdesc = doc.createElement("shortdesc")
shortdesc_text = doc.createTextNode("This section lists all the error messages.")
shortdesc.appendChild(shortdesc_text)
concept.appendChild(shortdesc)
conbody = doc.createElement("conbody")
section = doc.createElement("section")
p = doc.createElement("p")
dl = doc.createElement("dl")
for column in csv_data:
xml_entry = f'<dlentry><dt>{column[3]}</dt><dd><p>{column[4]}</p><p>{column[1]}</p></dd></dlentry>'
dl.appendChild(doc.createTextNode(xml_entry))
p.appendChild(dl)
section.appendChild(p)
conbody.appendChild(section)
concept.appendChild(conbody)
doc.appendChild(concept)
xml_string = doc.toprettyxml(encoding="UTF-8").decode("utf-8")
xml_string = xml_string.replace("<", "<")
xml_string = xml_string.replace("<=", "<=")
xml_string = xml_string.replace(">", ">")
xml_string = xml_string.replace("&", "&")
return xml_string
def write_xml(xml_string, output_file):
with open(output_file, "w", encoding="UTF-8") as f:
f.write(xml_string)
def main():
# Enter the CSV file's name
csv_file_name = input("Enter the name of the CSV file: ")
# Reading the CSV data
with open(csv_file_name, "r", encoding="UTF-8") as csvfile:
csv_data = list(csv.reader(csvfile, delimiter=";"))
csv_data = csv_data[1:]
# This rows prepare XML for each row
xml_string = prepare_xml(csv_data)
# Write the XML string to a file
output_file = "error_list.xml"
write_xml(xml_string, output_file)
if __name__ == "__main__":
main()