470,648 Members | 1,640 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,648 developers. It's quick & easy.

Learning Pyrex with libxml2

Hi, I'm trying to learn how to use Pyrex by converting some of the
libxml2 examples. I'm not having much luck - I can create a document,
but any attempt to create nodes causes a segfault.

The code I'm trying to port is io2.c (http://xmlsoft.org/examples/io2.c)

I've commented the couple lines that cause a problem for me.

cdef extern from "libxml/tree.h":
ctypedef xmlDocPtr
ctypedef xmlNodePtr
ctypedef xmlNsPtr
xmlDocPtr xmlNewDoc(unsigned char *)
xmlNodePtr xmlNewNode (xmlNsPtr, unsigned char *)
void xmlNodeSetContent (xmlNodePtr, unsigned char *)
xmlNodePtr xmlDocSetRootElement (xmlDocPtr, xmlNodePtr )
void xmlDocDumpFormatMemory (xmlDocPtr, unsigned char **, int *, int )
xmlNodePtr xmlNewChild (xmlNodePtr, xmlNsPtr, unsigned char *,
unsigned char *)
void xmlFreeDoc (xmlDocPtr)
void xmlFree (xmlDocPtr)

def testNewDoc():
cdef xmlNodePtr n
cdef xmlDocPtr doc
cdef unsigned char* xmlbuff
cdef int buffersize

doc = xmlNewDoc(<unsigned char *> "1.0")

## The following three lines cause a segfault
# n = xmlNewNode(None, <unsigned char *> "root")
# xmlNodeSetContent(n, <unsigned char *> "content")
# xmlDocSetRootElement(doc, n)

xmlDocDumpFormatMemory(doc, &xmlbuff, &buffersize, 1)
xmlFrag = <char* > xmlbuff
print "%d bytes in string" % len(xmlFrag)
print "[%s]" % xmlFrag

Jul 18 '05 #1
0 954

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Rene Olsthoorn | last post: by
10 posts views Thread by Kyler Laird | last post: by
27 posts views Thread by Julien Fiore | last post: by
11 posts views Thread by Jim Lewis | last post: by
1 post views Thread by cesar.ortiz | last post: by
2 posts views Thread by jianbing.chen | last post: by
reply views Thread by warner | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.