-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove-empty-namespace-declarations.py
executable file
·36 lines (26 loc) · 1.27 KB
/
remove-empty-namespace-declarations.py
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
import os
directory = "./OEBPS/texts"
def parse_xhtml_files(directory):
xhtml_files_found = False # Flag to track if any XHTML files are found
corrected_files = [] # List to store the names of the corrected files
for filename in os.listdir(directory):
if filename.startswith("L0") and filename.endswith(".xhtml"):
xhtml_files_found = True # Set the flag to True
filepath = os.path.join(directory, filename)
try:
with open(filepath, "r") as file:
content = file.read()
updated_content = content.replace(' xmlns=""', '')
with open(filepath, "w") as file:
file.write(updated_content)
corrected_files.append(filename) # Add the filename to the corrected files list
except Exception as e:
print(f"Error processing file '{filepath}': {str(e)}")
if not xhtml_files_found:
print("No XHTML files found in the specified directory.")
else:
print(f"Number of XHTML files corrected: {len(corrected_files)}")
print("Corrected files:")
for filename in corrected_files:
print(filename)
parse_xhtml_files(directory)