Skip to content

Can't parse XML into a rfl::Generic #614

@JX75

Description

@JX75

When parsing XML text into a rfl::Generic, the result is a boolean with value false.

`
#include
#include <rfl/xml.hpp>
#include <rfl/generic.hpp>
#include <rfl.hpp>

int main() {
rfl::Generic::Object cat;
cat["name"] = "Cachou";
cat["colour"] = "black";
cat["species"] = "cat";

auto xmlString = rfl::xml::write<"cat">(cat);
auto genericCatVariant = rfl::xml::read<rfl::Generic>(xmlString).value().variant();
auto type = genericCatVariant.index();

std::cout << std::format("XML content:\n{}\n", xmlString);

/*
    Shows this:

    XML content:
    <?xml version="1.0" encoding="UTF-8"?>
    <cat>
        <name>Cachou</name>
        <colour>black</colour>
        <species>cat</species>
    </cat>
*/

std::cout << std::format("Type index {}\n", type);

/*
    Shows this instead of 4 (Object):
    Type index 0
*/

if (type == 0) {
    std::cout << std::format("Boolean value {}\n", std::get<0>(genericCatVariant));
}
else {
    std::cout << "Not a boolean.";
}

/*
    Shows this:
    Boolean value false
*/

return 0;

}

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions