Last active
July 10, 2018 10:19
Incomplete XInclude Resolution for 2nd Level?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
import textwrap | |
from lxml import etree | |
def parse(xmlfile, xinclude=True): | |
try: | |
xmlparser = etree.XMLParser(collect_ids=False, recover=False) | |
tree = etree.parse(xmlfile, parser=xmlparser) | |
if xinclude: | |
tree.xinclude() | |
return 0 | |
except (etree.XMLSyntaxError, etree.XIncludeError) as err: | |
print("ERROR: %s" % err, file=sys.stderr) | |
print(textwrap.indent(str(err.error_log), prefix=" "), file=sys.stderr) | |
return 10 | |
if __name__ == "__main__": | |
result = parse(sys.argv[1]) | |
sys.exit(result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<section version="5.1" | |
xmlns="http://docbook.org/ns/docbook" | |
xmlns:xi="http://www.w3.org/2001/XInclude"> | |
<title>First Level</title> | |
<xi:include href="second.xml"/> | |
</section> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<article version="5.1" | |
xmlns="http://docbook.org/ns/docbook" | |
xmlns:xi="http://www.w3.org/2001/XInclude"> | |
<title>Test for nested XIncludes</title> | |
<xi:include href="first.xml"/> | |
</article> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<section version="5.1" | |
xmlns="http://docbook.org/ns/docbook"> | |
<title>Second</title> | |
<para>The quick brown fox.<!--</para>--> | |
</section> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment