RE: [xml] Problem with basic libxml functions



Hello.. both of u were perfectly right. I was assuming that the 
white-spaces in the xml file will be ignored. Thanks a lot.

Sagar

On Mon, 22 Mar 2004, Jesse Pelton wrote:

You need to understand how XML handles whitespace; see
http://www.w3.org/TR/2004/REC-xml-20040204/.  The text node to which Bill is
referring is the whitespace (newline + space characters) that you've used to
format your document. 

<terminal_preference>
</terminal_preference>

is not equivalent to

<terminal_preference></terminal_preference>

or

<terminal_preference/>

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
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
command,
his preference is remembered. (Bug no. 77300).
  I am storing the data in an xml file in the foll. format

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

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

<snip>

  //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;

<snip>

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"?>
<terminal_preference>
</terminal_preference>

  As is obvious from the code extract, the control enters 
the while
loop
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?

Regards
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.

Bill

_______________________________________________
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]