use the (included) jing library to validate the XML.

def jing(self, tag=None, schemas=None, schemafn=None, ext='.rnc'):
        """use the (included) jing library to validate the XML."""
        from . import JARS

        java = os.environ.get('java') or 'java'
        jingfn = os.path.join(JARS, 'jing.jar')
        tag = tag or self.root.tag
        schemas = schemas or self.schemas
        schemafn = schemafn or Schema.filename(tag, schemas, ext=ext)
        if schemafn is not None:
            cmd = [java, '-jar', jingfn, '-c', schemafn]
            if os.path.splitext(schemafn)[-1].lower() != '.rnc':
                cmd.pop(cmd.index('-c'))
            try:
                fn = self.fn
                if fn is None or not os.path.exists(fn):
                    tempf = tempfile.NamedTemporaryFile()
                    fn = tempf.name
                    tempf.close()
                    open(fn, 'wb').write(etree.tounicode(self.root).encode('utf-8'))
                subprocess.check_output(cmd + [fn])
            except subprocess.CalledProcessError as e:
                tbtext = html.unescape(str(e.output, 'UTF-8'))
                raise RuntimeError(tbtext).with_traceback(sys.exc_info()[2]) from None