AW: [xml] Re: Added new child to DOM tree does not have line breaks.


Well, this is about "ignorable whitespace". There is no real solution
to this.
The problem lies in the fact that the library cannot distinguish
between "ignorable whitespace" and "relevant whitespace". That is
why the library will not add any indenting to nodes already containing
When you read in an indented XML file, all your nodes will contain
text (the whitespaces from the indent).
If you add children to such nodes, there will be no indentig for
these too. You have to deal with the indenting yourself.
But if you "REALLY" know that your nodes containing only whitespace
are for indenting, you can use some function to delete the blank nodes
from the tree. I am using the following:

void RemoveBlankTextNodes(
   xmlNodePtr PpRoot) // root node: get with xmlDocGetRootElement()
        xmlNodePtr node;
        xmlNodePtr next;

        node = PpRoot->children;

        while(node != 0)
                next = node->next;

                node = next;

This is very risky, because you do not know why the nodes contain
only whitespace: because of indenting or because the node contains
relevant data which just happens to be whitespace.
So ignoring white space is at your risc!
Again: the best way is to generate the indenting yourself.

Servus -- Alfred

Alfred Mickautsch

schuler business solutions AG
Karl-Berner-Str. 4
D-72285 Pfalzgrafenweiler
tel:    +49 (0)74 45 830-184
fax:    +49 (0)74 45 830-349
e-mail: alfred mickautsch schuler-ag com

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