[libxml++] Preserving whitespace



> So the only thing we need is to call xmlKeepBlanksDefault(0), 
> which is done in  the parse_xx methods.
> The consequence is that, theoraticaly, the output will be 
> formatted only if something has been parsed before (I did not test this behavior).
> 
> I think that the most simple thing to do is to call 
> xmlKeepBlanksDefault(0) in write_to functions.
> On the other hand we'll have it called more than necessary. 
> So we could call it in Document::Init::Init() and remove it everywere else.

Along these lines, I've been meaning to ask:

I'd like to be able to output the text between <tag> ... </tag>
with exactly the same whitespace and formatting as when input.

This is supposedly the XML standard, according to my understanding
of when whitespace is and is not significant based on reading the
various XML standards docs.

libxml2 sems to support it, via xmlKeepBlanksDefault(1) as you mention
above.

However, I have not been able to get libxml++ to do it.
I have not investigated bypassing libxml++ and using libxml2
directly.

Reading the libxml++ code reveals several calls to xmlKeepBlanksDefault(0).
I have tried flipping them, to no effect.

---

So, the dumb question: using libxml++, how do I read
<foo>
    bar         bb
    big
    </foo>

and arrange it so that the text is exactly that,
"
    bar         bb
    big
    "
and not
"bar bb big"

?

Now, I may have embarassed myself, and it may be that the
XML rule is the latter rather than the former, but that's
not my understanding of the present standard.  The XML standards
committee mailing list has lots of discussion about when this changed.

PS I've also tried applying xml:space="preserve",
without luck.

====


By the way, something on my to do list:
Given
<foo>
<raw>
    bar         bb
    big
    </raw>
<foo>
I would like to be able to output indented text that preserves all
of the line break and whitespace info, e.g.

<foo>
  <raw>
    <line></line>
    <line>    bar         bb</line>
    <line>big</line>
    <line>    </line>
  </raw>
</foo>

i.e. using <line>..</line> to indicate line boundaries, 
with all whitespace preserved within <line>...</line>


I'd only do this for certain specified tags;
and I may or may not put xml:space="preserve".

====


Like I said, I haven't investigated this much.
But if
(a) libxml++ is supposed to preserve whitespace according
    to XML rules, and it's just me that is broken,
    please tell me
(b) if there is some magic incantation needed to get libxml++
    to preserve whitespace according to XML rules, please tell me
(b') code example appreciated.



====


Related:  libxml2 uses a number of global settings, such
as xmlKeepBlanksDefault(0).

It's not clear to me whether this are "captured", or are truly
live values.

E.g.  I might want to be processing multiple documents
at the same time, one of which preserves whitespace and one
which does not.  Is this safe with libxml2/libxml++?








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