def parse_vv_xml(xmlfile):
parse_vv_clear()
# Fix in XML File @see http://stackoverflow.com/a/7265260
# @see http://effbot.org/elementtree/elementtree-xmlparser.htm#tag-ET.XMLParser.entity
parser = ElementTree.XMLParser()
# TODO: UseForeignDTD is not compatible with Python 3
# parser.parser.UseForeignDTD(True)
parser.entity['nbsp'] = chr(0x160)
etree = ElementTree.ElementTree()
# Workaround for the UseForeignDTD problem
# if missing, adds DOCTYPE tag to handle and changes encoding to utf-8
doctype = '''<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE CourseCatalogue [<!ENTITY nbsp " ">]>\n'''
replace_first_line(xmlfile, doctype)
root = etree.parse(xmlfile, parser=parser).find('CourseCatalogueArea')
root_cat = ImportCategory.objects.create(parent=None, name='root', rel_level=None)
parse_vv_recurse(root, root_cat)
评论列表
文章目录