File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2121# filename -> title mapping to a xml file.
2222
2323import fnmatch
24+ import lxml .etree as e
2425import re
2526import os
2627
3132 html_files .append (os .path .join (root , filename ))
3233
3334# create an xml file containing mapping between page title and actual location
34- out = open ('link-map.xml' , 'w' )
35- out .write ('<?xml version="1.0" encoding="UTF-8"?><files>\n ' )
35+ root = e .Element ('files' )
3636
3737for fn in html_files :
3838 f = open (fn , "r" )
5151 title = m .group (1 )
5252
5353 target = os .path .relpath (os .path .abspath (fn ), os .path .abspath ('output' ))
54- out .write (' <file from="' + title + '" to="' + target + '" />\n ' )
54+ file_el = e .SubElement (root , 'file' )
55+ file_el .set ('from' , title )
56+ file_el .set ('to' , target )
5557
56- out .write ('</files>' )
58+ out = open ('link-map.xml' , 'w' )
59+ out .write ('<?xml version="1.0" encoding="UTF-8"?>' )
60+ out .write (e .tostring (root , pretty_print = True ))
5761out .close ()
You can’t perform that action at this time.
0 commit comments