vtkXMLDataParser is broken
Description:
It is actually the same error described here. The Arch VTK package cannot read VTK files:
( 24.361s) [paraview ] vtkXMLParser.cxx:375 ERR| vtkXMLDataParser (0x594129186810): Error parsing XML in stream at line 22, column 25, byte index 1327: not well-formed (invalid token)
( 24.374s) [paraview ] vtkXMLReader.cxx:520 ERR| vtkXMLUnstructuredGridReader (0x594128f09520): Error parsing input file. ReadXMLInformation aborting.
Additional info:
- package version(s): 9.3.0-8
- config and/or log files:
- link to upstream bug report, if any: https://discourse.paraview.org/t/i-cannot-read-a-vtp-file-i-could-open-yesterday-can-someone-try-to-open-it/13938
I tried the following expat code, using the expat Arch package, on this file:
#include <expat.h>
#include <stdio.h>
#include <string.h>
#define BUFFER_SIZE 100000
/* track the current level in the xml tree */
static int depth = 0;
static char *last_content;
/* first when start element is encountered */
void
start_element(void *data, const char *element, const char **attribute)
{
int i;
for (i = 0; i < depth; i++) {
printf(" ");
}
printf("%s", element);
for (i = 0; attribute[i]; i += 2) {
printf(" %s= '%s'", attribute[i], attribute[i + 1]);
}
printf("\n");
depth++;
}
/* decrement the current level of the tree */
void
end_element(void *data, const char *el)
{
int i;
for (i = 0; i < depth; i++) {
printf(" ");
}
printf("Content of element %s was \"%s\"\n", el, last_content);
depth--;
}
void
handle_data(void *data, const char *content, int length)
{
char *tmp = (char*)malloc(length);
strncpy(tmp, content, length);
tmp[length] = '\0';
data = (void *) tmp;
last_content = tmp; /* TODO: concatenate the text nodes? */
}
int
parse_xml(char *buff, size_t buff_size)
{
FILE *fp;
fp = fopen("ref.vtu", "r");
if (fp == NULL) {
printf("Failed to open file\n");
return 1;
}
XML_Parser parser = XML_ParserCreate(NULL);
XML_SetElementHandler(parser, start_element, end_element);
XML_SetCharacterDataHandler(parser, handle_data);
memset(buff, 0, buff_size);
printf("strlen(buff) before parsing: %d\n", strlen(buff));
size_t file_size = 0;
file_size = fread(buff, sizeof(char), buff_size, fp);
/* parse the xml */
if (XML_Parse(parser, buff, strlen(buff), XML_TRUE) == XML_STATUS_ERROR) {
printf("Error: %s\n", XML_ErrorString(XML_GetErrorCode(parser)));
}
fclose(fp);
XML_ParserFree(parser);
return 0;
}
int
main(int argc, char **argv)
{
int result;
char buffer[BUFFER_SIZE];
result = parse_xml(buffer, BUFFER_SIZE);
printf("Result is %i\n", result);
return 0;
}
And it seems that the VTK is loaded just fine. However, I also tried to recompile the VTK library with the option -DVTK_MODULE_USE_EXTERNAL_VTK_expat=ON
, but I got the same error. So I suppose expat is just ok, and the problem is in VTK itself.
Steps to reproduce:
- Download the vtp file from the discussion: https://discourse.paraview.org/uploads/short-url/mmC8dLkm86pEai3nsLYNQcRDyLX.vtp
- Try to load it in VTK
Edited by Jose Luis Cercos Pita