Re: [xml] Problems when using several free functions



Quoting Pinho external infineon com:

Hi There,

      First of all I'm new to the world of C and libxml, and due to my OO
background (mainly JAVA) I don't master the ways of pointers, and I'm
having
a hard time to get some things right using libxml.

      The program that I'm developing is using xPath in a massive way,
it's a kind of XML document comparer, but, it doesn't care about the
order
of it's elements, so with xPath it's very easy to compare two elements
even
if thay have a different order in the XMLDocument.

      To get this done I'm using xPath API and some structs from tree API
like xmlDocPtr or xmlNode, etc...

      The program reads a XML document string and then parse it's
(xmlParseDoc(stringWithXmlDoc)), then, depending on the kind of
structure
that I find (simple, complex, array, etc) I do diferent things. 
      I always use xmlXPathEvalExpression to get the node that I want and
then use the returned node to compare the values and the inner structure
of
some xml elements to see if they are equal. To travel trough all the
Xml
document I use a recursive function. 

      
      I have 2 problems:

      I wanted to initialize the context only once, outside that recursive
function, and then call the recursive function, when I do this, at the
2nd
or 3th level of recursion the xmlXPathEvalExpression returns null, just
like
the context changed, this is strange because I've done nothing to the
context !?!? If I do the parsing of the string (call the xmlParseDoc
function again) and then create the context at each recursive call
it's
works fine, if I try to initiate the context only once, I get the
problem
described. 
When an XPath expression is evaluated, the current node (ctxt->node) in the 
context is set to the result of the evaluation. Depending upon where you want 
your search to start from, you may need to reset the current node. In any case 
you should not have to reparse the document or create a new context.


      Another problem that I'm having is when I use the functions to free
the libxml objects, sometimes I get a invalid access error (before the
call
to the xmlFreeXXXX I test the variable to see if it's null). Is there
another test I must do before calling the xmlFreeXXX functions? When
must I
call the function xmlFreeXXX, only when the API tells me to?





Any help is very welcome,


Thank You

Luís Pinho
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/
xml gnome org
http://mail.gnome.org/mailman/listinfo/xml





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