File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / libxml2 / python / tests / relaxng.py
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Sun Jun 15 19:53:34 2014 UTC (10 years, 3 months ago) by misho
Branches: libxml2, MAIN
CVS tags: v2_9_1p0, v2_9_1, HEAD
libxml2 2.9.1

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>