Re: [xml] an appropriate strcpy



On Fri, Feb 07, 2003 at 10:45:40AM -0500, Nick Torenvliet wrote:
I'm trying to get the name of an element into a string so I can pass it 
out into a function. I tried looking for a libxml function to do this but I 
couldn't find one so I tried using regular old strcpy.  Using strcpy works 
fine until the segmentation fault that occurs when xmlSaveFormatFile.

Anyways I am guessing there is a better way to extract the name into an 
xmlChar * or a char * .  You have any ideas?

  node->name is an UTF8 encoded 0 terminated string (xmlChar *)
However there is various kind of nodes, and sometime you may get
an xmlAttrPtr or an xmlDocumentPtr or an xmlNsPtr in the nodeset.
You need to check first node->type and if necessary cast the pointer
appropriately. For example if the node is an xmlDocumentPtr then
the structure allocated has no name and using the name field without
checking nor casting can perfectly lead to an invalid pointer reference.
See xmlXPathDebugDumpNodeList() in xpath.c and xmlDebugDumpOneNode()
in debugXML.c for example

Daniel

-- 
Daniel Veillard      | Red Hat Network https://rhn.redhat.com/
veillard redhat com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]