Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: a080cf84cb0b4e18f83c2066ece0d53ca8da27c6 (plain) (blame)
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
# ###############################################################################
# Copyright (c) 2014 CEA LIST.
#
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Eclipse Public License 2.0
# which accompanies this distribution, and is available at
# https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation
#
# ###############################################################################

"""
API for the serialization of pretty-printed XML files
"""

# encoding of the XML files
XML_ENCODING = "UTF-8"
# identation string
XML_IDENT = "\t"
# new line string
XML_NEWLINE = "\n"


def output(document, file):
    """
    Outputs the XML document in the given file with pretty printing
    :param document: The XML document to serialize
    :param file: The file to output to
    :return: None
    """
    document.normalize()
    content = XML_NEWLINE.join(
        [line for line in document.toprettyxml(XML_IDENT, XML_NEWLINE, XML_ENCODING).split(XML_NEWLINE) if
         line.strip()])
    result = open(file, "w")
    result.write(content)
    result.close()

Back to the top