awacke1 commited on
Commit
4c38937
β€’
1 Parent(s): 34128f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -83,12 +83,12 @@ def get_table_download_link(file_path):
83
  href = f'<a href="data:{mime_type};base64,{b64}" target="_blank" download="{file_name}">{file_name}</a>'
84
  return href
85
 
86
- def CompressXML(xml_text, max_length):
87
  root = ET.fromstring(xml_text)
88
  for elem in list(root.iter()):
89
  if isinstance(elem.tag, str) and 'Comment' in elem.tag:
90
  elem.parent.remove(elem)
91
- return ET.tostring(root, encoding='unicode', method="xml")[:max_length]
92
 
93
  def read_file_content(file,max_length):
94
  if file.type == "application/json":
@@ -100,8 +100,8 @@ def read_file_content(file,max_length):
100
  elif file.type == "application/xml" or file.type == "text/xml":
101
  tree = ET.parse(file)
102
  root = tree.getroot()
103
- #return ET.tostring(root, encoding='unicode')
104
- return CompressXML(ET.tostring(root, encoding='unicode',max_length))
105
  elif file.type == "text/markdown" or file.type == "text/md":
106
  md = mistune.create_markdown()
107
  content = md(file.read().decode())
 
83
  href = f'<a href="data:{mime_type};base64,{b64}" target="_blank" download="{file_name}">{file_name}</a>'
84
  return href
85
 
86
+ def CompressXML(xml_text):
87
  root = ET.fromstring(xml_text)
88
  for elem in list(root.iter()):
89
  if isinstance(elem.tag, str) and 'Comment' in elem.tag:
90
  elem.parent.remove(elem)
91
+ return ET.tostring(root, encoding='unicode', method="xml")
92
 
93
  def read_file_content(file,max_length):
94
  if file.type == "application/json":
 
100
  elif file.type == "application/xml" or file.type == "text/xml":
101
  tree = ET.parse(file)
102
  root = tree.getroot()
103
+ xml = CompressXML(ET.tostring(root, encoding='unicode')
104
+ return xml(:max_length)
105
  elif file.type == "text/markdown" or file.type == "text/md":
106
  md = mistune.create_markdown()
107
  content = md(file.read().decode())