Print output in a single line in tinyxml

1.3k Views Asked by At

I am using TinyXML to save and print XML documents.

While printing the document I am getting:

<document>
   <data>1</data>
   <data>2</data>
   <data>3</data>
</document>

as result.

But I want the result to be printed in a single line like this:

<document><data>1</data><data>2</data><data>3</data></document>

How can I do this?

1

There are 1 best solutions below

2
On

Based on the documentation (copied below), I assume you're using Print or Save, so you get "pretty printed" output

enter image description here

but as you see from the alternatives above and also from this documentation, you can instead use the << operator to output directly to an ostream, where the documentation says

Note that this outputs without any newlines or formatting, as opposed to Print(), which includes tabs and new lines.

So to save to a file, something like this

     TiXmlPrinter printer;
     printer.SetStreamPrinting();
     base.Accept( &printer );
     out << printer.Str();
     return out;