RE: RE: [xml] clarification about "empty" text nodes



Hmm, try checking if it has a child, for example (No error checking)

xmlDocPtr doc;
xmlNodePtr cur;

doc=xmlParseFile(XML_File);

cur=xmlDocGetRootElement(doc);
cur=cur->xmlChildrenNode;
while(cur!=NULL)
{
        if(cur->type!=3)
        {
                // Do what you want, continue down the tree with recursion
and 
                // cur=cur->xmlChildrenNode, or whatever
                // If you want the value, do 
                // xmlNodeListGetString(doc,cur->xmlChildrenNode,1);
        }
        if(cur!=NULL)
                cur=cur->next;
}


-----Original Message-----
From: oliverst online de [mailto:oliverst online de] 
Sent: Wednesday, February 11, 2004 12:50 PM
To: Ron Ohmer
Cc: xml gnome org
Subject: Re: RE: [xml] clarification about "empty" text nodes


err, no.

Look at this example:

<Node>
    <Node1>Value</Node1>
<Node>

If I take the pointer to "Node" and do a xmlNodeGetContent() on it, I
get formatting stuff for the whole underlying tree. Same witha pointer
to "Node1" gives me "Value" as result. The problem is, that I can't
determinate it by the type as "Node" is type 1 (XML_ELEMENT_NODE) and it
has a child with the name "text" of type 3 (XML_TEXT_NODE) and it
contains the formatting stuff. "Node1" is the same type and has the same
type as child with the name "text" and it contains "Value". By simple
type-checking it doesn't work.

"Node"(XML_ELEMENT_NODE)
-> childs 
"text"(XML_TEXT_NODE)
"Node1"(XML_ELEMENT_NODE)
xmlNodeGetContent() result -> formatting chars for underlying tree
(always beginning with 0x0a???)

Node1(XML_ELEMENT_NODE)
->childs
"text"(XML_TEXT_NODE)
xmlNodeGetContent() result -> "Value"

Ron Ohmer <rohmer aisconsulting net> schrieb am 11.02.2004, 17:05:59:
Just check the type..

Type 3 is one of your "Empty" text nodes (i.e. Formatting Whitespace)
Type 1 is a value.


-----Original Message-----
From: xml-admin gnome org [mailto:xml-admin gnome org] On Behalf Of
oliverst online de
Sent: Wednesday, February 11, 2004 6:10 AM
To: xml gnome org
Subject: [xml] clarification about "empty" text nodes


I got a function, which gets a node and reads the content of it. The
problem is, that in some cases it might be a node, that has no text. In
that case I get the whole tree as formated text, because libxml2 stores
such formatting chars in the "empty" text nodes. And because that
content of the text nodes isn't empty I can just verify an empty text
node, when I check the first char of "content" for 0x0a. Is that right?
_______________________________________________
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]