XML-mas – Fixing ‘Error parsing XML at line…’
I recently came across an issue which I had never seen before, and I thought I’d share my experience and the fix that I found using the Tableau .xml which lies beneath the workbook. This issue itself is quite rare, but if it does occur then this is one approach to solving this particular problem.
Sometimes Tableau becomes corrupt; one such issue is the “Error parsing XML at line <insert any number here> of file…” when opening your workbook. This is when you think you’ve really screwed up. Tableau’s Knowledge Base article recommends you send it over to them if the workbook is shown as bigger than 0kb which can take time to send over and get back. Though, as that article says, if your workbook says it’s 0kb… You gotta start over.
But if it is a file that’s bigger than 0KB then all is not lost! You can try this solution if it works for you, but in order to carry out this solution, you will need;
- Your Tableau workbook in .twb format
- Note: if you have saved it as a .twbx file, all you need to do is navigate to where you’ve stored it on your computer, right-click and select ‘Unpackage’ and it will partition the Tableau workbook (.twb) from the rest of the data.
- A text editor program such as Notepad++
- The example I’m about to show uses Notepad++ as the XML editing tool
Got these? Good! Let’s go and rescue that workbook.
I’m going to use my own case study here as an example.
When I was presented with this issue, I tried a host of different things before deciding to open the .twb in Notepad++.
But why would you open it in Notepad++ the first place? And what exactly is an XML of a Tableau Workbook?
As this response on the Tableau Community (which is an awesome place to troubleshoot, learn and hone your Tableau skills) by Jonathan Drummey states, a .twb file is an XML file which contains the metadata for a Tableau workbook.
When you open it, it looks a bit like this:
This XML of the .twb includes data source connections, dashboards, worksheets, colours used, parameters and virtually everything that allows the workbook to function. When I opened the workbook and navigated to the line which threw the error (My error message stated ‘Error parsing XML at line 411386…’), this is the view which greeted me.
Huh – These are ‘NULL’ values at the end of the XML, highlighted above –
Perhaps it was trying to write some more XML before the computer crashed or something similar. The first thing I tried was to simply delete all the NULL files on this line and open it up again. No dice.
Then after racking my brain a little, I thought I’d compare the end of this .twb to another ‘healthy’ .twb file that I had. What the XML of *that* file looked like is below.
Bingo! This is the solution I’m after.
What seems to have happened is, as the computer crashed and the file has become corrupt, the final wrappings of the metadata hasn’t been completed, meaning the XML file is left open ended and incomplete. I’ve highlighted and blown up what I mean by wrappings with the xml tags at the end of the workbook.
To test this theory, I copied the three parts here; the end parts (shown above) and pasted it into my damaged .twb to replace where the NULL symbols were.
And just like magic, the workbook sprung back to life!
I probably should add that I’m sure there’s more detail to working with the XML of a Tableau Workbook than I have described here, and I should say that this XML is super important so shouldn’t be overly messed around with if you’re unsure what consequences what you’re doing will have. The only other time I had encountered a use for this method to look ‘under the hood’ of a .twb file, was to change all instances of the ‘9.1’ to ‘9.0’ during customer projects while at the Data School. This trick meant that if we’d accidentally created something in the Tableau 9.1 beta and wanted to share it with the customer after the project was done, they would be able to open the file in Tableau 9.0.
But hopefully this will solve at least one other person’s problem when presented with the ‘Error parsing XML at line X of the file: no element found’ in Tableau.