The command
xmllint -pretty 2 example.xml
converts
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE EXAMPLE SYSTEM "example.dtd" [
<!ENTITY xml "Extensible Markup Language">
]>
<example>&xml;<example1>text</example1><example2>text</example2></example>
to
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE EXAMPLE SYSTEM "example.dtd" [
<!ENTITY xml "Extensible Markup Language">
]>
<example
>&xml;<example1
>text</example1
><example2
>text</example2
></example
>
It's looks strange. Spaces and linefeeds are added within the tags.
Therefore the meaning of the document is not changed. The problem
with adding characters the way you want is that all characters
(including leading and trailing blanks and linefeeds) in character
data may be significant.
I'm sure it would be possible to add this kind of formatting to
xmlpp::Document.
Kjell
2012-01-29 22:20, carlo esposito skrev:
Can not be that nobody
has thought .....
I test tomorrow and I will
'know !!!
It's absurd to think to insert linefeeds
and spaces
....is really very tedious :(
----Messaggio originale----
Da: kjell ahlstedt bredband net
Data: 29/01/2012 17.11
A: "carlo esposito"<kevinstar libero it>
Cc: <libxmlplusplus-list gnome org>
Ogg: Re: R: Re: How to use libxml++ to write a file in c ++ xml
The Document::write_*_formatted() methods turn off formatting in
an element that contains a child node of type TextNode,
CdataNode, or EntityReference, and recursively in all the
element's child elements. It's not libxml++'s fault. It's how
the underlying libxml2 functions behave.
I have not found this behaviour documented anywhere. I had to
check libxml2's source code to understand what's going on. If
you're interested, look at http://git.gnome.org/browse/libxml2/tree/xmlsave.c
function xmlNodeDumpOutputInternal() line 944. (The line number
may change, if the file is edited.) Obviously the behaviour is
by design. Probably we have to accept it. If you think it's
worth the trouble, you can file a libxml2 bug. At least it would
be fine to have the behaviour documented.
Of course you can get the output you want by adding text nodes
with all the linefeeds and spaces that you want, but it would be
tedious.
Kjell
|