| @@ -23,7 +23,7 @@ def formatHTML(source: str, prettify: bool) -> str: | |||||||
|         return html.tostring(htmlDoc).decode().replace("\n", "").replace(">    ", ">") |         return html.tostring(htmlDoc).decode().replace("\n", "").replace(">    ", ">") | ||||||
|     return etree.tostring(htmlDoc, encoding='unicode', pretty_print=True) |     return etree.tostring(htmlDoc, encoding='unicode', pretty_print=True) | ||||||
|  |  | ||||||
| def formatXML(source: str) -> str: | def formatXML(source: str, prettify: bool) -> str: | ||||||
|     """Method used to format XML |     """Method used to format XML | ||||||
|  |  | ||||||
|     :param source: XML to format |     :param source: XML to format | ||||||
| @@ -46,7 +46,10 @@ def formatXML(source: str) -> str: | |||||||
|     parser = etree.XMLParser(remove_blank_text=True) |     parser = etree.XMLParser(remove_blank_text=True) | ||||||
|     xml = etree.parse(byte_input, parser=parser) |     xml = etree.parse(byte_input, parser=parser) | ||||||
|  |  | ||||||
|     return prolog + etree.tostring(xml, pretty_print=False).decode() |     if prettify: | ||||||
|  |         prolog += "\n" | ||||||
|  |  | ||||||
|  |     return prolog + etree.tostring(xml, pretty_print=prettify).decode() | ||||||
|  |  | ||||||
|  |  | ||||||
| def xpath(source: str, xpath: str) -> str: | def xpath(source: str, xpath: str) -> str: | ||||||
|   | |||||||
| @@ -36,8 +36,8 @@ def process_xml(request: request, type: str) -> str: | |||||||
|             response_json['result'] = Parser.xslt(data, processorData) |             response_json['result'] = Parser.xslt(data, processorData) | ||||||
|         elif (type == "xpath"): |         elif (type == "xpath"): | ||||||
|             response_json['result'], response_json['type'] = Parser.xpath(data, processorData) |             response_json['result'], response_json['type'] = Parser.xpath(data, processorData) | ||||||
|         # elif (type == "prettify"): |         elif (type == "prettify"): | ||||||
|         #     response_json['result'] = Parser.formatXML(data, True) |             response_json['result'] = Parser.formatXML(data, True) | ||||||
|         elif (type == "minimize"): |         elif (type == "minimize"): | ||||||
|             response_json['result'] = Parser.formatXML(data, False) |             response_json['result'] = Parser.formatXML(data, False) | ||||||
|         elif (type == "prettifyHtml"): |         elif (type == "prettifyHtml"): | ||||||
| @@ -77,10 +77,9 @@ def xsd(): | |||||||
| def xslt(): | def xslt(): | ||||||
|     return process_xml(request, "xslt") |     return process_xml(request, "xslt") | ||||||
|  |  | ||||||
| # Removed because lxml can't pretify <xs:complexType mixed="true"> | @app.route("/prettify", methods=["POST"]) | ||||||
| # @app.route("/prettify", methods=["POST"]) | def prettify(): | ||||||
| # def prettify(): |     return process_xml(request, "prettify") | ||||||
| #     return process_xml(request, "prettify") |  | ||||||
|  |  | ||||||
| @app.route("/minimize", methods=["POST"]) | @app.route("/minimize", methods=["POST"]) | ||||||
| def minimize(): | def minimize(): | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user