3 # this tests the entities substitutions with the XmlTextReader interface
9 str_io = StringIO.StringIO
14 schema="""<element name="foo" xmlns="http://relaxng.org/ns/structure/1.0"
15 datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
17 <element name="label">
31 # Memory debug specific
32 libxml2.debugMemory(1)
35 # Parse the Relax NG Schemas
37 rngp = libxml2.relaxNGNewMemParserCtxt(schema, len(schema))
38 rngs = rngp.relaxNGParse()
42 # Parse and validate the correct document
45 <label>some text</label>
50 input = libxml2.inputBuffer(f)
51 reader = input.newTextReader("correct")
52 reader.RelaxNGSetSchema(rngs)
58 print("Error parsing the document")
61 if reader.IsValid() != 1:
62 print("Document failed to validate")
66 # Parse and validate the incorrect document
69 <label>some text</label>
74 # RNG errors are not as good as before , TODO
75 #expect="""RNG validity error: file error line 3 element text
76 #Type byte doesn't allow value '1000'
77 #RNG validity error: file error line 3 element text
78 #Error validating datatype byte
79 #RNG validity error: file error line 3 element text
80 #Element item failed to validate content
82 expect="""Type byte doesn't allow value '1000'
83 Error validating datatype byte
84 Element item failed to validate content
87 def callback(ctx, str):
89 err = err + "%s" % (str)
90 libxml2.registerErrorHandler(callback, "")
93 input = libxml2.inputBuffer(f)
94 reader = input.newTextReader("error")
95 reader.RelaxNGSetSchema(rngs)
101 print("Error parsing the document")
104 if reader.IsValid() != 0:
105 print("Document failed to detect the validation error")
109 print("Did not get the expected error message:")
120 libxml2.relaxNGCleanupTypes()
122 # Memory debug specific
123 libxml2.cleanupParser()
124 if libxml2.debugMemory(1) == 0:
127 print("Memory leak %d bytes" % (libxml2.debugMemory(1)))