falcong / pugixml

Automatically exported from code.google.com/p/pugixml
0 stars 0 forks source link

Line breaks in Windows #61

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
In pugixml 0.5 in Visual Studio 2005, xml_document::save_file() outputs 
line breaks (newlines) as LF (linefeed, 0x0A) instead of CR+LF (carriage 
return + linefeed, 0x0D 0x0A). I am using pugixml to create a new file 
from scratch.

Original issue reported on code.google.com by derek.ho...@gmail.com on 25 May 2010 at 1:13

GoogleCodeExporter commented 9 years ago
I do not know yet if this is a bug or a feature; it's possible that the next 
version 
will have a corresponding save flag.

In the meantime, you can save your document to a file/stream that's open 
without the 
binary flag yourself, i.e.:

FILE* file = fopen(filename, "w");
if (file)
{
    pugi::xml_writer_file writer(file);
    doc.save(writer);
}

Original comment by arseny.k...@gmail.com on 25 May 2010 at 7:54

GoogleCodeExporter commented 9 years ago
What about just:

doc.save(std::ofstream(filename));
?

Original comment by jopi...@gmail.com on 30 Nov 2011 at 9:05

GoogleCodeExporter commented 9 years ago
Yes, that should work as well. There are several viable workarounds, if you can 
use STL then probably the shortest one is using ofstream.

Original comment by arseny.k...@gmail.com on 30 Nov 2011 at 4:03

GoogleCodeExporter commented 9 years ago
I can't change the default behavior for several reasons:
- This is a compatibility-breaking change (however minor)
- More importantly, saving file as text is noticeably slower with MSVC CRT (of 
course, the actual impact depends on I/O involved, disk flushing policies, etc.)

I've added an optional flag pugi::format_save_file_text; passing this flag to 
save_file will open the file as text.
This was added to trunk as of r884; the change will go into the next pugixml 
version as well.

Original comment by arseny.k...@gmail.com on 23 Mar 2012 at 5:43