Exemplo n.º 1
0
bool XMLDocument::saveToHTMLFile(const std::string & filename, const bool indent) const
{
    int ret;
    int options = XML_SAVE_AS_HTML;
    if (indent)
    {
        options |= XML_SAVE_FORMAT;
    }

    xmlThrDefIndentTreeOutput(1);
    xmlSaveCtxtPtr ctxt = xmlSaveToFilename(filename.c_str(), 0, options);
    ret = xmlSaveDoc(ctxt, document);
    xmlSaveFlush(ctxt);
    xmlSaveClose(ctxt);

    return ret != -1;
}
Exemplo n.º 2
0
const std::string XMLDocument::dumpHTML(bool indent) const
{
    xmlBuffer * buffer = xmlBufferCreate();
    int ret;
    int options = XML_SAVE_AS_HTML;
    if (indent)
    {
        options |= XML_SAVE_FORMAT;
    }

    xmlThrDefIndentTreeOutput(1);
    xmlSaveCtxtPtr ctxt = xmlSaveToBuffer(buffer, 0, options);
    ret = xmlSaveDoc(ctxt, document);
    xmlSaveFlush(ctxt);
    xmlSaveClose(ctxt);

    std::string str((const char *)xmlBufferDetach(buffer));
    xmlBufferFree(buffer);

    return str;
}
Exemplo n.º 3
0
bool XMLDocument::saveToFile(const std::string & filename, const bool indent) const
{
    xmlThrDefIndentTreeOutput(1);
    return xmlSaveFormatFile(filename.c_str(), document, indent) != -1;
}
Exemplo n.º 4
0
int main(int argc, const char *argv[])
{
    LIBXML_TEST_VERSION

    xmlLineNumbersDefault(1);
    xmlThrDefIndentTreeOutput(1);
    xmlKeepBlanksDefault(0);
    xmlThrDefTreeIndentString("  ");

    std::vector<std::string> arguments(argv + 1, argv + argc);

    if (arguments.empty()) {
        usage();
    }

    // Scan for global options
    for (std::string arg : arguments) {
        if (arg.substr(0, 2) != "--") {
            break;
        }
        if (arg == "--version") {
            std::cout << "pharmmltool " VERSION << std::endl;
            exit(0);
        } else if (arg == "--help") {
            usage();
        } else {
            std::cout << "Unknown option: " << arg << std::endl;
            usage();
        }
    }

    // Read command
    std::string command_string = arguments[0];
    arguments.erase(arguments.begin() + 0);

    Command command;
    if (command_string == "validate") {
        command = Command::validate;
    } else if (command_string == "indent") {
        command = Command::indent;
    } else if (command_string == "compact") {
        command = Command::compact;
    } else if (command_string == "version") {
        command = Command::version;
    } else if (command_string == "convert") {
        command = Command::convert;
    } else {
        std::cout << "Unknow command: " << command_string << std::endl;
        usage();
    }

    // Read command options
    std::vector<std::string> remaining_arguments;
    std::string target_version = "0.9";
    std::string schema_path;

    for (std::string arg : arguments) {
        if (arg.compare(0, 14, "--schema-path=") == 0) {
            if (command == Command::validate) {
                schema_path = arg.substr(14, std::string::npos);
            } else {
                error("Option --schema-path can only be used with the validate command");
            }
        } else if (arg.compare(0, 17, "--target-version=") == 0) {
            if (command == Command::convert) {
                target_version = arg.substr(17, std::string::npos);
                if (target_version != "0.8.1" && target_version != "0.9") {
                    error("Unknown PharmML version " + target_version + ". Can only convert to PharmML 0.8.1 or PharmML 0.9");
                }
            } else {
                error("Option --target-version can only be used with the convert command");
            }
        } else {
            remaining_arguments.push_back(arg);
        }
    } 

    int numargs = remaining_arguments.size();
    if (!(command == Command::convert && numargs == 2 ||
            command == Command::validate && numargs == 1 ||
            command == Command::indent && numargs == 1 ||
            command == Command::compact && numargs == 1 ||
            command == Command::version && numargs == 1)) {
        error("Wrong number of arguments");
    }

    if (command == Command::validate) {
        auto auxpath = auxfile_path(argv[0]);
        validate(remaining_arguments[0], schema_path, auxpath, "PharmML");
    } else if (command == Command::indent) {
        indent(remaining_arguments[0], true);
    } else if (command == Command::compact) {
        indent(remaining_arguments[0], false);
    } else if (command == Command::version) {
        std::string pharmml_version = version(remaining_arguments[0], "PharmML");
        std::cout << pharmml_version << std::endl;
    } else if (command == Command::convert) {
        auto auxpath = auxfile_path(argv[0]);
        auxpath /= fs::path{"transformations"};
        convert(remaining_arguments[0], remaining_arguments[1], target_version, auxpath);
    }

    return 0;
}