Server IP : 127.0.0.2 / Your IP : 18.117.166.111 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /usr/share/doc/python-libxml2/examples/ |
Upload File : |
#!/usr/bin/python -u import libxml2 import sys # Memory debug specific libxml2.debugMemory(1) doc = libxml2.newDoc("1.0") comment = doc.newDocComment("This is a generated document") doc.addChild(comment) pi = libxml2.newPI("test", "PI content") doc.addChild(pi) root = doc.newChild(None, "doc", None) ns = root.newNs("http://example.com/doc", "my") root.setNs(ns) elem = root.newChild(None, "foo", "bar") elem.setBase("http://example.com/imgs") elem.setProp("img", "image.gif") doc.saveFile("tmp.xml") doc.freeDoc() doc = libxml2.parseFile("tmp.xml") comment = doc.children if comment.type != "comment" or \ comment.content != "This is a generated document": print("error rereading comment") sys.exit(1) pi = comment.next if pi.type != "pi" or pi.name != "test" or pi.content != "PI content": print("error rereading PI") sys.exit(1) root = pi.next if root.name != "doc": print("error rereading root") sys.exit(1) ns = root.ns() if ns.name != "my" or ns.content != "http://example.com/doc": print("error rereading namespace") sys.exit(1) elem = root.children if elem.name != "foo": print("error rereading elem") sys.exit(1) if elem.getBase(None) != "http://example.com/imgs": print("error rereading base") sys.exit(1) if elem.prop("img") != "image.gif": print("error rereading property") sys.exit(1) doc.freeDoc() # Memory debug specific libxml2.cleanupParser() if libxml2.debugMemory(1) == 0: print("OK") else: print("Memory leak %d bytes" % (libxml2.debugMemory(1))) libxml2.dumpMemory()