Read XML, change values, write back: Crippled file

Trying to read an XML file (here: a Scribus file), change some values, and write the changed XML back to a file.

When trying this using encoding/xml, I end up with a crippled file.

Here is my code:

And here is a test file:

The resulting changed file should be able to be opened with Scrubus but I can’t get it to work.

Any help appreciated.

1 Like

Thanks for your help @rot13.

  • Added the <?xml version="1.0" encoding="UTF-8"?> - this was easy (similar to
  • Newline at the end - does not matter, Scribus can read files with and without newlines at the end
  • <TableBorderLine Width="1" PenStyle="1" Color="Black" Shade="100"/> gets rewritten to <TableBorderLine Width="1" PenStyle="1" Color="Black" Shade="100"></TableBorderLine> - not nice since it increases the file size, but Scribus can read the file nevertheless
  • Randomly inserted LF &#xA; and spaces - this is the real problem. Why is this happening, what am I doing wrong?

Manually replacing the &#xA; with nothing does fix the file. But it’s a crude workaround.

According to I am supposed to add ,innerxml to the struct definition but for the heck of it I can’t seem to get it to work.

For example, I have

type SCRIBUSUTF8NEW struct {
	XMLName  xml.Name `xml:"SCRIBUSUTF8NEW"`

How do I add the required ,innerxml there?

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.