2017-05-01 08:26:56 +08:00
|
|
|
#!/usr/bin/env python3
|
2020-11-09 12:23:58 +08:00
|
|
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
2013-03-30 02:22:27 +08:00
|
|
|
|
2014-02-12 13:55:38 +08:00
|
|
|
from lxml import etree as tree
|
2013-03-30 02:22:27 +08:00
|
|
|
|
2014-02-12 13:55:38 +08:00
|
|
|
class CustomResolver(tree.Resolver):
|
|
|
|
def resolve(self, url, id, context):
|
|
|
|
if 'custom-entities.ent' in url:
|
|
|
|
return self.resolve_filename('man/custom-entities.ent', context)
|
2013-03-30 02:22:27 +08:00
|
|
|
|
2014-02-12 15:58:41 +08:00
|
|
|
_parser = tree.XMLParser()
|
|
|
|
_parser.resolvers.add(CustomResolver())
|
2017-11-19 00:32:46 +08:00
|
|
|
|
2014-02-12 15:58:41 +08:00
|
|
|
def xml_parse(page):
|
|
|
|
doc = tree.parse(page, _parser)
|
|
|
|
doc.xinclude()
|
|
|
|
return doc
|
2017-11-19 00:32:46 +08:00
|
|
|
|
2014-02-12 15:58:41 +08:00
|
|
|
def xml_print(xml):
|
|
|
|
return tree.tostring(xml, pretty_print=True, encoding='utf-8')
|