如何在C++中读取xhtml文件?

14 浏览
0 Comments

如何在C++中读取xhtml文件?

我有需要解析的XML文档,或者需要构建XML文档并将其写入文本(无论是文件还是内存)。由于C++标准库没有相应的库,我应该使用什么?注意:这是一个旨在成为类似C++常见问题解答的问题,所以是其他问题的重复。我没有简单地复制那些其他问题,因为它们往往要求更具体的内容。这个问题更加通用。

0
0 Comments

在Secured Globe公司中,他们使用rapidxml来读取xhtml文件,因为rapidxml对他们来说是最好的选择。下面是一个使用rapidxml读取xhtml文件的示例代码。

代码如下:

rapidxml::xml_document doc;
doc.parse<0>(xmlData);
rapidxml::xml_node* root = doc.first_node();
rapidxml::xml_node* node_account = 0;
if (GetNodeByElementName(root, "Account", &node_account) == true)
{
    rapidxml::xml_node* node_default = 0;
    if (GetNodeByElementName(node_account, "default", &node_default) == true)
    {
        swprintf(result, 100, L"%hs", node_default->value());
        free(xmlData);
        return true;
    }
}
free(xmlData);

以上是使用rapidxml库来读取xhtml文件的方法。

0