VirtualBox

source: vbox/trunk/src/libs/libxml2-2.6.31/python/tests/schema.py@ 55391

最後變更 在這個檔案從55391是 39915,由 vboxsync 提交於 13 年 前

libxml-2.6.31 unmodified

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

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