VirtualBox

source: vbox/trunk/src/libs/libxml2-2.13.2/python/tests/relaxng.py@ 108403

最後變更 在這個檔案從108403是 105420,由 vboxsync 提交於 8 月 前

libxml2-2.12.6: Applied and adjusted our libxml2 changes to 2.12.6. bugref:10730

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:executable 設為 *
檔案大小: 1.2 KB
 
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
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette