IssueID #1487: added helper script for fixing xml ids

This commit is contained in:
Cyprian Laskowski 2020-11-19 17:00:55 +01:00
parent 743ee6ebae
commit 8e4133d45e

21
scripts/fix_xml_ids.py Normal file
View File

@ -0,0 +1,21 @@
import argparse
import codecs
import re
arg_parser = argparse.ArgumentParser(description='Fix invalid XML ids.')
arg_parser.add_argument('-infile', type=str, help='Input file')
arg_parser.add_argument('-outfile', type=str, help='Output file')
arguments = arg_parser.parse_args()
input_file_name = arguments.infile
output_file_name = arguments.outfile
output_file = codecs.open(output_file_name, 'w')
input_file = codecs.open(input_file_name, 'r')
for line in input_file:
line = re.sub('xml:id="(?=\d)','xml:id="s', line)
line = line.replace('#', '#s')
output_file.write(line)
input_file.close()
output_file.close()