Re: [xml] 2Bugs in xmlTextReaderExpand()



On Wed, Jul 16, 2003 at 11:36:46PM +0200, Berlinez Oussorov fhtw-berlin de wrote:
Hallo

I use libxml2.5.8 and in xmlTextReaderExpand() Function
is 2 bugs. The pruduced Node with the subtree contains more Nodes
then the subtree should. If i print rekursiv all Subtree-Nodes 
with
children and next - elements i can see this. 

  Your code is very hard to read.


...
name = xmlTextReaderLocalName(reader);
    if(name != NULL){
        if (strcmp(name,"bvclsadr")==0){


  this is not sufficient test, you may visit element nodes twice,
check the documentation and the type too.

             node = xmlTextReaderExpand(reader);
             verarbeite(node);           /*Print nodes rekursive 
hier*/

  this also print the next siblings and their subtree hence the problem

             ret = xmlTextReaderNext(reader);
        }
...

    void
verarbeite( node )
    xmlNodePtr node;
{
    xmlChar *name=NULL;
    xmlChar *value=NULL;
    xmlChar *content=NULL;

    if(node != NULL){
    /*For this Node print all children and next Nodes*/
        if(node->type == XML_ELEMENT_NODE){
            printf("<%s>",node->name);
        }
        if(node->type == XML_TEXT_NODE){
            if((value = node->content) != NULL){
                printf("%s",po_strdelbtn(value)); /*a trim() 
- Function*/

   if this really does a trim (i.e. both side of the string),
then po_strdelbtn has to leak or not be thread safe, looks poor...

            }
        }

        /*all Child Nodes rekursive*/
        if(node->children!=NULL){
            if(node->children->type==XML_ELEMENT_NODE){
                printf("\n\t");
            }
            verarbeite(node->children);
        }
        if(node->type == XML_ELEMENT_NODE){
            printf("</%s>",node->name);
        }
        /*all Next Elemente rekursive*/
        if(node->next!=NULL){
            if(node->next->type==XML_ELEMENT_NODE){
                printf("\n\t");
            }
            verarbeite(node->next);

 This also print the siblings of the returned node, no garantee
is provided by Expand, all you know is that the subtree of the given
node is expanded, that's all.

xmlTextReaderRead() call...Nr:2
<bvclsadr>
        <BOVACSA>00001</BOVACSA>
        <LANR>nr2001</LANR>
        <ANRED>Herr</ANRED>
        <VSAD1>Name1</VSAD1>
        <VSAD2>Name2</VSAD2>
        <VSAD3>Name3</VSAD3></bvclsadr>
        <bvclsadr>
        <BOVACSA>00002</BOVACSA>
        <LANR>nr2002</LANR>
        <ANRED>Herr</ANRED>
        <VSAD1>Name1</VSAD1>
        <VSAD2>Name2</VSAD2>
        <VSAD3>Name3</VSAD3></bvclsadr>
        <bvclsadr>
        <BOVACSA>00003</BOVACSA>
        <LANR></LANR></bvclsadr>

  Normal, the chunk processed was more than the first bvclsadr

xmlTextReaderRead() call...Nr:4
<bvclsadr>
        <BOVACSA>00003</BOVACSA>
        <LANR></LANR></bvclsadr>
xmlTextReaderRead() call...Nr:5

xmlTextReaderRead() call...Nr:6

As you see at output between Reader() calls 4 and 5 
the Expand Function has build invalid Tree. That is
the second bug. Sometimes Expand - Function produces
invalid Node.

  I'm not sure about this, you don't even give the full code, I can't
see if you stop on <bvclsadr/> too and not just <bvclsadr>.
Provide a complete small python example using the serialize() call
for dumping instead of your own routine and I will check what's happening
really.

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]