f = StringIO(
    """<element name="a" xmlns="http://relaxng.org/ns/structure/1.0">
 <zeroOrMore>
    <element name="b">
      <text />
    </element>
 </zeroOrMore>
</element>
"""
    )
relaxng_doc = etree.parse(f)
relaxng = etree.RelaxNG(relaxng_doc)
valid = StringIO('<a><b></b></a>')
doc = etree.parse(valid)
How do I validate XML document using RELAX NG schema in Python?