1

I'm running the following code snippet on Windows:

root = Base.source_dir()
s = read(joinpath(root,"dialog.glade"), String)
# b = GtkBuilder(filename=joinpath(root, "dialog.glade")) # works fine
b = GtkBuilder(buffer=s) # error
...get objects, etc

I'm getting the following:

LoadError: Error on line 77 char 2: Document must begin with an element (e.g. <book>)

What am I doing wrong?

Minimal glade file that reproduces the fault:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<interface>
  <requires lib="gtk+" version="3.24"/>
  <object class="GtkDialog" id="win">
  </object>
</interface>

This has 8 lines, the last being an empty line. The reported error is at line 8 char 2.

John Trinder
  • 127
  • 4
  • This does not appear to be a general issue (i.e. other glade files work well with both methods). Could you produce a minimum working example of the glade file that causes the issue? Also, some details about this `dialog.glade` - how many lines it has, what line 77 contains, etc. - could also help. – Sundar R Mar 04 '22 at 18:18
  • Have added the glade xml data to the original post. – John Trinder Mar 04 '22 at 19:00
  • Ah, as I thought - can you try a `readchomp` in place of the `read` in the code? – Sundar R Mar 04 '22 at 19:06
  • Nope, this time it's line 7 char 14 – John Trinder Mar 04 '22 at 19:19
  • Replaced partial glade file with a minimal example. – John Trinder Mar 04 '22 at 19:46
  • 2
    FYI I'm unable to reproduce the problem with the given minimal file (even after adding an extra blank line). But maybe it has to do with using Windows line endings (CR+LF) - though I'm not sure why that would only be in specific lines. Can you verify what characters are on the last line? On Linux I would do `tail -n 1 minimal.glade | hexdump` and check that there's only `000a` (ignoring the first column) in the output, not sure what tools you have available on the Windows setup. – Sundar R Mar 04 '22 at 20:00
  • I have 0x0A at the end of the last line – John Trinder Mar 04 '22 at 21:41
  • Using s=read(str, String) and show(s) I get the following: "\n\n\n \n \n \n\n" – John Trinder Mar 04 '22 at 21:45
  • I did the following in which the file consists of the minimal code: fpath = joinpath(Base.source_dir(), "dialog2.glade"); sb = read(fpath); s = read(fpath,String); Vector{UInt8}(s)==sb true – John Trinder Mar 05 '22 at 00:17

0 Answers0