VirtualBox

source: vbox/trunk/src/libs/libxml2-2.6.30/python/tests/schema.py@ 11632

Last change on this file since 11632 was 6076, checked in by vboxsync, 17 years ago

Merged dmik/s2 branch (r25959:26751) to the trunk.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Revision Author Id
File size: 1.3 KB
Line 
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
Note: See TracBrowser for help on using the repository browser.

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