VirtualBox

source: vbox/trunk/src/libs/libxml2-2.12.6/python/tests/schema.py@ 105635

最後變更 在這個檔案從105635是 104106,由 vboxsync 提交於 10 月 前

libxml2-2.9.14: Applied and adjusted our libxml2 changes to 2.9.14. bugref:10640

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:executable 設為 *
檔案大小: 1.3 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" encoding="iso-8859-1"?>
10<schema xmlns = "http://www.w3.org/2001/XMLSchema">
11 <element name = "Customer">
12 <complexType>
13 <sequence>
14 <element name = "FirstName" type = "string" />
15 <element name = "MiddleInitial" type = "string" />
16 <element name = "LastName" type = "string" />
17 </sequence>
18 <attribute name = "customerID" type = "integer" />
19 </complexType>
20 </element>
21</schema>"""
22
23instance="""<?xml version="1.0" encoding="iso-8859-1"?>
24<Customer customerID = "24332">
25 <FirstName>Raymond</FirstName>
26 <MiddleInitial>G</MiddleInitial>
27 <LastName>Bayliss</LastName>
28</Customer>
29"""
30
31ctxt_parser = libxml2.schemaNewMemParserCtxt(schema, len(schema))
32ctxt_schema = ctxt_parser.schemaParse()
33ctxt_valid = ctxt_schema.schemaNewValidCtxt()
34doc = libxml2.parseDoc(instance)
35ret = doc.schemaValidateDoc(ctxt_valid)
36if ret != 0:
37 print("error doing schema validation")
38 sys.exit(1)
39
40doc.freeDoc()
41del ctxt_parser
42del ctxt_schema
43del ctxt_valid
44libxml2.schemaCleanupTypes()
45
46# Memory debug specific
47libxml2.cleanupParser()
48if libxml2.debugMemory(1) == 0:
49 print("OK")
50else:
51 print("Memory leak %d bytes" % (libxml2.debugMemory(1)))
52
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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