Skip to content

XML parse error with mfast::dynamic_templates_description for FAST 1.1 XML Templates #160

@Zamilan3330

Description

@Zamilan3330

Hi, I’m encountering a persistent XML parse error when using mfast::dynamic_templates_description to parse FAST 1.1 XML template files. The error occurs with both a minimal test template and a complex production template. I’m hoping for insights into what might be causing this or suggestions for further debugging.

Error:
When parsing XML templates with mfast::dynamic_templates_description, I get:

TinyXML2 parsed XML successfully
Attempting to parse XML file with mFAST: /home/zamilan/projects/mFAST/projects/<xml_file>
Standard exception: XML parse error

This occurs for:

A minimal template (minimal_templates.xml):

<?xml version="1.0" encoding="UTF-8"?>
<templates xmlns="http://www.fixprotocol.org/ns/fast/td/1.1">
    <template name="MinimalTemplate" id="1" dictionary="MinimalTemplate">
        <string name="MessageType" id="1" presence="mandatory"><constant value="X"/></string>
        <uInt32 name="SeqNum" id="2" presence="mandatory"><increment/></uInt32>
    </template>
</templates>

Code:
The test program (xml_test.cpp):

#include <mfast/xml_parser/dynamic_templates_description.h>
#include <mfast/exceptions.h>
#include <iostream>
#include <fstream>
#include <string>
#include <unistd.h>
#include <tinyxml2.h>

void test_xml(const char* xml_path, const char* template_ns = nullptr) {
    try {
        std::cout << "\nTesting file: " << xml_path << std::endl;
        std::ifstream xml_file(xml_path);
        if (!xml_file.is_open()) {
            throw std::runtime_error("Cannot open XML file: " + std::string(xml_path));
        }
        std::cout << "XML file content:" << std::endl;
        std::string content((std::istreambuf_iterator<char>(xml_file)), std::istreambuf_iterator<char>());
        std::cout << content << std::endl;
        xml_file.close();

        // Check for BOM
        if (!content.empty() && (unsigned char)content[0] == 0xEF && (unsigned char)content[1] == 0xBB && (unsigned char)content[2] == 0xBF) {
            std::cerr << "Warning: UTF-8 BOM detected in XML file" << std::endl;
            content.erase(0, 3);
        }

        // tinyxml2 parse
        tinyxml2::XMLDocument doc;
        tinyxml2::XMLError error = doc.LoadFile(xml_path);
        if (error != tinyxml2::XML_SUCCESS) {
            std::cerr << "TinyXML2 error: " << doc.ErrorName() << " (" << error << ") at line " << doc.ErrorLineNum() << std::endl;
            return;
        }
        std::cout << "TinyXML2 parsed XML successfully" << std::endl;

        // mFAST parse
        std::cout << "Attempting mFAST parse (ns: " << (template_ns ? template_ns : "null") << "): " << xml_path << std::endl;
        mfast::dynamic_templates_description description(xml_path, template_ns, mfast::template_registry::instance());
        std::cout << "mFAST parse successful" << std::endl;
    } catch (const mfast::fast_error& e) {
        std::cerr << "mFAST error: " << e.what() << std::endl;
    } catch (const std::exception& e) {
        std::cerr << "Standard exception: " << e.what() << std::endl;
    } catch (...) {
        std::cerr << "Unknown exception occurred" << std::endl;
    }
}

int main() {
    char cwd[1024];
    if (getcwd(cwd, sizeof(cwd))) {
        std::cout << "Current working directory: " << cwd << std::endl;
    }
    const char* ns = "http://www.fixprotocol.org/ns/fast/td/1.1";
    test_xml("/home/zamilan/projects/mFAST_old/projects/minimal_templates.xml", ns);
    test_xml("/home/zamilan/projects/mFAST_old/projects/millennium_fast_templates.xml", ns);
    return 0;
}

I Tried:

Verified XML Syntax: tinyxml2 parses both XML files successfully, ruling out syntax issues.
Minimal Template: Created minimal_templates.xml with dictionary, , and to isolate the issue, but it still fails.
Namespace Variations: Tested mfast::dynamic_templates_description with template_ns = "http://www.fixprotocol.org/ns/fast/td/1.1" and nullptr.
BOM Check: Added code to detect and remove UTF-8 BOM, but no BOM was found.
Content-Based Parsing: Tried dynamic_templates_description(std::string content) with file content, same error.
Template Registry: Linked template_registry.cpp, but its implementation is unknown (not shared yet). Tried a minimal template_registry:

// template_registry.h
#ifndef TEMPLATE_REGISTRY_H
#define TEMPLATE_REGISTRY_H
#include <mfast/xml_parser/dynamic_templates_description.h>
class template_registry : public mfast::template_registry {
public:
    template_registry() {}
    void add(const mfast::template_description* desc) override {
        mfast::template_registry::add(desc);
    }
};
#endif

// template_registry.cpp
#include "template_registry.h"
Library Dependencies: Verified libmfast_xml_parser.so links to libtinyxml2.a using ldd. No version info found in libmfast*.so via strings.
fast_type_gen: Attempted to regenerate millennium_fast_templates.{h,cpp,inl} with fast_type_gen, but its compatibility with mFAST_old is unclear.
mFAST Source Inspection: Checked /usr/local/include/mfast/xml_parser/dynamic_templates_description.h and templates_builder.h, confirming reliance on template_registry_impl.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions