Better error messaging for corrupt odt file

Request For Enhancement, User feedback candidates for wiki
Post Reply
EddieM
Posts: 4
Joined: Fri Jan 13, 2023 3:45 pm

Better error messaging for corrupt odt file

Post by EddieM »

I am writing an application that generates an Odt writer file. It is still rudimentary but works. I occasionally do something dumb that causes the odt file to be un-readable when OO Writer tries to open it. Is there a way to turn on more specific error messaging? Or, perhaps, a separate Odt file analyzer for analyzing the issue? I’m not interested in commercial products; everything I’m doing uses open apps and the final product will be open.
The error message is usually just the line and column number of the end of the content.xml file. Not very helpful. I usually have to start backing out changes until I find the error. Painful to say the least.
About about the app. The application is a stamp album page generator. I’m using C++ with wxWidgets for gui, xml handling and zipping and VisualCode IDE. The generated Odt is structurally reasonably simple. It amounts to frames within frames within frames with an occasional image and short text name. It reads a template of an empty Odt file and adds the style and content xml.
Thanks,
Eddie
OpenOffice.7.3.4.2 on Linux Mint 19.x
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Better error messaging for corrupt Odt file.

Post by John_Ha »

EddieM wrote: Fri Jan 13, 2023 4:12 pm The error message is usually just the line and column number of the end of the content.xml file.
There is no better message.

LO is telling you it got to the end of your XML and, bearing in mind there is no more XML, there must be a error in the previous XML. It could be many things but is probably a matching tag is missing.

Put your XML into an XML validator to find your error.

Note that LO doesn't make XML errors in what it writes so the error message is for people who do "unsupported" things like write their own XML; or for corrupted files.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
EddieM
Posts: 4
Joined: Fri Jan 13, 2023 3:45 pm

Re: Better error messaging for corrupt Odt file.

Post by EddieM »

John_Ha wrote: Fri Jan 13, 2023 6:03 pm Note that LO doesn't make XML errors in what it writes so the error message is for people who do "unsupported" things like write their own XML;
I am routinely accused of "coloring outside the lines". It's a lot more interesting. ;)
I always make the initial assumption that it is I who has screwed up. And that usually turns out to be the case.
I was hoping there is some way to get a little more info especially because I am doing unsupported things.
In most of the cases where I have had trouble finding the issue it has not been a malformed XML structure but things like an attribute of a node having a misspelled name or value. i.e., something like "conten" instead of "content". I can load the content.XML into VisualCode and do a pretty print and see that it is fine.
I've used XML Copy Editor but that barfs on the first node "office:document-content" of a file freshly created from OO writer. It says there is no no declaration found. but it all looks good to me. ( Yes, that is not an issue for this forum.) I'm not an expert at XML and especially not the ODT spec.

Eddie
OpenOffice.7.3.4.2 on Linux Mint 19.x
User avatar
RoryOF
Moderator
Posts: 34619
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Better error messaging for corrupt Odt file.

Post by RoryOF »

I suggest you make a trivial OpenOffice file, by using OpenOffice Writer or Calc (or as appropriate), Then use XML Copy Editor to examine the content.xml and note the header lines; that will give you what you need for your file generator.

XML Copy Editor has a serious drawback in my view - it refuses to pretty print an XML file with errors. I would prefer to use an XML editor that pretty printed up to the error.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
EddieM
Posts: 4
Joined: Fri Jan 13, 2023 3:45 pm

Re: Better error messaging for corrupt Odt file.

Post by EddieM »

RoryOF wrote: Fri Jan 13, 2023 8:58 pm I suggest you make a trivial OpenOffice file, by using OpenOffice Writer or Calc (or as appropriate),
That is exactly what I am doing. My start is a clean OpenOffice Writer file. I read and write the content.xml, etc. with wxWidgets XML classes to add style info and Frame and image content info.. It works and I keep adding formatting to make it prettier. That's when i do something wrong and suddenly it doesn't work. If I catch it quick enough then where the mistake is is pretty well known. If I've added a bunch of stuff (that just has to be right; it compiles :roll: ) that is when problems get hard to find.

Eddie
OpenOffice.7.3.4.2 on Linux Mint 19.x
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Better error messaging for corrupt Odt file.

Post by John_Ha »

Notepad++ with the XML addon is quite good. It has a validator.

Google XML validator for lots.

If you upload the file someone may be able to find the problem
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
EddieM
Posts: 4
Joined: Fri Jan 13, 2023 3:45 pm

Re: Better error messaging for corrupt Odt file.

Post by EddieM »

Thanks. I have worked through the current problems and am now adding stuff again. For example, i need to make some frames transparent. Though that is easy from Writer I need to figure out how writer does it and how to make my code duplicate it. It looks like some funny business going on. I was hoping there was some additional methods of seeing what was happening but it looks like I'm doing everything I can with the available tools. Just a lot of diffing, reading, searching, and head scratching.
So I guess this thread could be marked as solved (I don't know how to do that either.) since it it identifies all the methods I'm already doing.
Thanks for the help.
I'm sure I'll be back.
This is a heck of a way to have fun...
Eddie
OpenOffice.7.3.4.2 on Linux Mint 19.x
User avatar
robleyd
Moderator
Posts: 5087
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia

Re: Better error messaging for corrupt Odt file.

Post by robleyd »

As you are using Linux, you should have xmllint available to you - perhaps it may be of some help.
Cheers
David
OS - Slackware 15 64 bit
Apache OpenOffice 4.1.15
LibreOffice 24.2.2.2; SlackBuild for 24.2.2 by Eric Hameleers
John_Ha
Volunteer
Posts: 9584
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: Better error messaging for corrupt Odt file.

Post by John_Ha »

LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
Post Reply