I want to write an xml to a zip file, this is what I tried:
zip_open("new.zip", write, Z, []),
zipper_open_new_file_in_zip(Z, "imsmanifest.xml", S, []),
xml_write(S, element(elem, [], []), []),
close(S),
close(Z).
An error is raised on the encoding:
Call: (15) sgml_write:xml_write(<stream>(000002284659f7e0), element(elem, [], []), []) ? skip
ERROR: Domain error: `xml_encoding' expected, found `octet'
Can I specify this somewhere?
jan
September 16, 2026, 3:40pm
2
xml_write/3 wants a text stream. This works fine.
t :-
setup_call_cleanup(
zip_open("new.zip", write, Z, []),
setup_call_cleanup(
zipper_open_new_file_in_zip(Z, "imsmanifest.xml", S, []),
( set_stream(S, encoding(utf8)),
xml_write(S, element(elem, [], []), [])
),
close(S)),
zip_close(Z)).
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).