You may like to use library(archive) though. library(zip) is a small public layer with a much more limited interface than library(archive) that exposes the built-in zip functionality (SWI-Prolog saved states are zip files).
…as tradition requires, a problem is only solved if one or more new problems are raised xml_write does not seem to add “newlines” in the zip file (in normal textfiles, it does).
You surely need layout(true) as otherwise it adds no white space at all. There is no final newline. One might argue there should be when layout is used. It is not required by XML though. Simply call nl(S) after the xml_write …
Its too long ago. I think it has rules for that. Check the code (or ask AI to see how to do that ) Note that you cannot add white space characters in an XML document except for in the tag, e.g., you can do something like this.
<mytag
>Content</mytag
>
Inside an element, white space is part of the content. SWI-Prolog’s XML parser has options to avoid that, but these are not XML compliant. This is from my memory; I happily forgot most about XML’s details …
But, it could produce fair layout for RDF/XML, so it can do some of this Who wants XML since we have JSON