VirtualBox

source: vbox/trunk/src/libs/libxml2-2.13.2/python/tests/schema.py@ 105420

Last change on this file since 105420 was 105420, checked in by vboxsync, 7 months ago

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

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 1.3 KB
Line 
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
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