1

I am using tinyxml2 and the system saves my xmls with 4 spaces for indents instead of a tab. The program that reads this only reads in tabs and is giving me errors. Is there anyway I can change tinyxml2 to use tab instead of 4 spaces ? I have tried

    XMLDocument xmlDoc(true, PRESERVE_WHITESPACE);

but it is not changing anything

Kong
  • 2,202
  • 8
  • 28
  • 56

1 Answers1

1

I'm assuming you're saving the xml document by calling XMLDocument::SaveFile(const char* filename, bool compact=false) (or XMLDocument::SaveFile(FILE* fp, bool compact=false) ).

These methods use the XMLPrinter class which writes 4 spaces for the indentation of elements (method XMLPrinter::PrintSpace). You can suppress writing of indentation and newlines by passing true for the compact parameter to SaveFile. Compact is preferred when passing xml directly from one application to another. And maybe your program will accept xml in this form.

Changing the indentation character(s) will require that you overload XMLPrinter to provide your own implementation of PrintSpace and overload XMLDocument to use your XMLPrinter.

Note that whitespace (newlines and indentation) between elements in a XML document has no significance and will be (must be) ignored by conforming parsers. It is for human readability only.

PRESERVE_WHITESPACE / COLLAPSE_WHITESPACE only affects how whitespace characters are handled in within the text node of an element.

stanthomas
  • 1,141
  • 10
  • 9