3 # this tests the entities substitutions with the XmlTextReader interface
9 schema="""<element name="foo" xmlns="http://relaxng.org/ns/structure/1.0"
10 datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
12 <element name="label">
26 # Memory debug specific
27 libxml2.debugMemory(1)
30 # Parse the Relax NG Schemas
32 rngp = libxml2.relaxNGNewMemParserCtxt(schema, len(schema))
33 rngs = rngp.relaxNGParse()
37 # Parse and validate the correct document
40 <label>some text</label>
44 f = StringIO.StringIO(docstr)
45 input = libxml2.inputBuffer(f)
46 reader = input.newTextReader("correct")
47 reader.RelaxNGSetSchema(rngs)
53 print "Error parsing the document"
56 if reader.IsValid() != 1:
57 print "Document failed to validate"
61 # Parse and validate the incorrect document
64 <label>some text</label>
69 expect="""RNG validity error: file error line 3 element text
70 Type byte doesn't allow value '1000'
71 RNG validity error: file error line 3 element text
72 Error validating datatype byte
73 RNG validity error: file error line 3 element text
74 Element item failed to validate content
77 def callback(ctx, str):
79 err = err + "%s" % (str)
80 libxml2.registerErrorHandler(callback, "")
82 f = StringIO.StringIO(docstr)
83 input = libxml2.inputBuffer(f)
84 reader = input.newTextReader("error")
85 reader.RelaxNGSetSchema(rngs)
91 print "Error parsing the document"
94 if reader.IsValid() != 0:
95 print "Document failed to detect the validation error"
99 print "Did not get the expected error message:"
110 libxml2.relaxNGCleanupTypes()
112 # Memory debug specific
113 libxml2.cleanupParser()
114 if libxml2.debugMemory(1) == 0:
117 print "Memory leak %d bytes" % (libxml2.debugMemory(1))