RE: [xml] Problem with basic libxml functions

You need to understand how XML handles whitespace; see  The text node to which Bill is
referring is the whitespace (newline + space characters) that you've used to
format your document. 


is not equivalent to




unless you provide a DTD the indicates the whitespace should be ignored.

I imagine the code you've snipped assumes child_of_cur points to a list of
children, but text node have no children.

-----Original Message-----
From: William M. Brack [mailto:wbrack mmm com hk] 
Sent: Sunday, March 21, 2004 6:15 AM
To: Sagar Rastogi
Cc: xml gnome org
Subject: Re: [xml] Problem with basic libxml functions

Sagar Rastogi said:
Hi Sagar

       I am working on an enhancement to make the panel-run-dialog
"smart", i.e. it should be able to remember whether the user wanted
to run
a command in terminal or not. So next time the user runs the same
his preference is remembered. (Bug no. 77300).
    I am storing the data in an xml file in the foll. format

<?xml version="1.0"?>
                <name> Program name like "galeon" or "nautilus"
                <terminal> true or false </terminal>

I am using libxml functions to parse/write to the xml file. I have
them exactly in the way specified in examples. Foll is a code


    //cur points to root node at the start.
    cur = cur->xmlChildrenNode;
        printf("Reaches here 3.2 \n");  //This gets printed
        //cur points to command
        while(cur) {
                printf("Reaches here 3.3 \n"); //This gets printed
                child_of_cur = cur->xmlChildrenNode;


Ah, a most unfortunate spot to "snip"... I can see what you have
done with the variable "child_of_cur", but I have absolutely no way
to tell what you do in the following lines with it or with the
variable "cur".  Certainly the cause of your "crash" is not on these
specific lines of code, but probably somewhere later in the loop.

The contents of my xml file are:

<?xml version="1.0"?>

    As is obvious from the code extract, the control enters 
the while
when it shouldn't. The program crashes at the line:

Hmmm... well, it's not obvious to *me* why it shouldn't enter the
while loop.  Your element <terminal_preference> looks to me like it
has text content which will be a child node, so I would expect it to
enter the loop.

 child_of_cur = cur->xmlChildrenNode
    Could somebody please tell me what is the error here?

Sagar Rastogi

I heartily recommend to you that you learn to use the gdb debugger,
and step through your code.  That should help you to see where you
are going wrong.


xml mailing list, project page
xml gnome org

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