1#!/usr/bin/env python3 2import sys 3import setup_test 4import libxml2 5 6# Memory debug specific 7libxml2.debugMemory(1) 8 9# 10# Testing XML document serialization 11# 12doc = libxml2.readDoc( 13"""<?xml version="1.0" encoding="iso-8859-1"?> 14<!DOCTYPE test [ 15<!ELEMENT test (#PCDATA) > 16<!ATTLIST test xmlns:abc CDATA #FIXED "http://abc.org" > 17<!ATTLIST test abc:attr CDATA #FIXED "def" > 18]> 19<test /> 20""", None, None, libxml2.XML_PARSE_DTDATTR) 21elem = doc.getRootElement() 22attr = elem.hasNsProp('attr', 'http://abc.org') 23print(attr.serialize()) 24if attr == None: 25 print("Failed to find defaulted attribute abc:attr") 26 sys.exit(1) 27 28doc.freeDoc() 29 30# Memory debug specific 31libxml2.cleanupParser() 32if libxml2.debugMemory(1) == 0: 33 print("OK") 34else: 35 print("Memory leak %d bytes" % (libxml2.debugMemory(1))) 36