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 # RNG errors are not as good as before , TODO
70 #expect="""RNG validity error: file error line 3 element text
71 #Type byte doesn't allow value '1000'
72 #RNG validity error: file error line 3 element text
73 #Error validating datatype byte
74 #RNG validity error: file error line 3 element text
75 #Element item failed to validate content
77 expect
="""Type byte doesn't allow value '1000'
78 Error validating datatype byte
79 Element item failed to validate content
82 def callback(ctx
, str):
84 err
= err
+ "%s" % (str)
85 libxml2
.registerErrorHandler(callback
, "")
87 f
= StringIO
.StringIO(docstr
)
88 input = libxml2
.inputBuffer(f
)
89 reader
= input.newTextReader("error")
90 reader
.RelaxNGSetSchema(rngs
)
96 print "Error parsing the document"
99 if reader
.IsValid() != 0:
100 print "Document failed to detect the validation error"
104 print "Did not get the expected error message:"
115 libxml2
.relaxNGCleanupTypes()
117 # Memory debug specific
118 libxml2
.cleanupParser()
119 if libxml2
.debugMemory(1) == 0:
122 print "Memory leak %d bytes" % (libxml2
.debugMemory(1))