# Initialize the field that contain the xml in memory
self.xmlroot = etree.Element(rootname, attrib = attrib)
- def escapeSequence(self, aStr):
- """
- See xml specification:
- The ampersand character(&) and the left angle bracket(<) MUST NOT appear in their
- literal form, except when used as markup delimiters, or within a comment, a processing
- instruction, or a CDATA section.
- If they are needed elsewhere, they MUST be escaped using either numeric character references
- or the strings '&' and '<' respectively.
- The right angle bracket(>) may be
- represented using the string '>', and MUST,
- for compatibility, be escaped using either '>' or a character reference
- when it appears in the string " ]]> " in content,
- when that string is not marking the end of a CDATA section.
- You can use these escape sequences:
- < (less - than) as < or <
- > (greater - than) as > or >
- & (ampersand) as &
- ' (apostrophe or single quote) as '
- " (double-quote) as "
- """
- replaces = [ ('&', '&'),
- ('>', '>'),
- ('<', '<'),
- ("'", '''),
- ('"', '"'),
- ]
- res = aStr
- for ini, fin in replaces: # order matters
- res = res.replace(ini, fin)
- return res
-
-
def write_tree(self, stylesheet=None, file_path = None):
'''Write the xml tree in the log file path. Add the stylesheet if asked.
if len(stylesheet) > 0:
f.write("<?xml-stylesheet type='text/xsl' href='%s'?>\n" % stylesheet)
f.write(etree.tostring(xmlroot, encoding='utf-8'))
- f.close()
+ f.close()
+
+def escapeSequence(aStr):
+ """
+ See xml specification:
+ The ampersand character(&) and the left angle bracket(<) MUST NOT appear in their
+ literal form, except when used as markup delimiters, or within a comment, a processing
+ instruction, or a CDATA section.
+ If they are needed elsewhere, they MUST be escaped using either numeric character references
+ or the strings '&' and '<' respectively.
+ The right angle bracket(>) may be
+ represented using the string '>', and MUST,
+ for compatibility, be escaped using either '>' or a character reference
+ when it appears in the string " ]]> " in content,
+ when that string is not marking the end of a CDATA section.
+ You can use these escape sequences:
+ < (less - than) as < or <
+ > (greater - than) as > or >
+ & (ampersand) as &
+ ' (apostrophe or single quote) as '
+ " (double-quote) as "
+ """
+ replaces = [ ('&', '&'),
+ ('>', '>'),
+ ('<', '<'),
+ ("'", '''),
+ ('"', '"'),
+ ]
+ res = aStr
+ for ini, fin in replaces: # order matters
+ res = res.replace(ini, fin)
+ return res
+