1#!/usr/bin/env python3 2import setup_test 3import libxml2 4import sys 5 6# Memory debug specific 7libxml2.debugMemory(1) 8 9schema="""<?xml version="1.0"?> 10<element name="foo" 11 xmlns="http://relaxng.org/ns/structure/1.0" 12 xmlns:a="http://relaxng.org/ns/annotation/1.0" 13 xmlns:ex1="http://www.example.com/n1" 14 xmlns:ex2="http://www.example.com/n2"> 15 <a:documentation>A foo element.</a:documentation> 16 <element name="ex1:bar1"> 17 <empty/> 18 </element> 19 <element name="ex2:bar2"> 20 <empty/> 21 </element> 22</element> 23""" 24instance="""<?xml version="1.0"?> 25<foo><pre1:bar1 xmlns:pre1="http://www.example.com/n1"/><pre2:bar2 xmlns:pre2="http://www.example.com/n2"/></foo>""" 26 27rngp = libxml2.relaxNGNewMemParserCtxt(schema, len(schema)) 28rngs = rngp.relaxNGParse() 29ctxt = rngs.relaxNGNewValidCtxt() 30doc = libxml2.parseDoc(instance) 31ret = doc.relaxNGValidateDoc(ctxt) 32if ret != 0: 33 print("error doing RelaxNG validation") 34 sys.exit(1) 35 36doc.freeDoc() 37del rngp 38del rngs 39del ctxt 40libxml2.relaxNGCleanupTypes() 41 42# Memory debug specific 43libxml2.cleanupParser() 44if libxml2.debugMemory(1) == 0: 45 print("OK") 46else: 47 print("Memory leak %d bytes" % (libxml2.debugMemory(1))) 48 49