在 C++ 中使用 RapidXML 写入 XML 文件
write to an xml file using rapidxml in c++
#include "rapidxml-1.13/rapidxml.hpp"
#include "rapidxml-1.13/rapidxml_print.hpp"
#include "rapidxml-1.13/rapidxml_utils.hpp"
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace rapidxml;
int main()
{
std::ofstream theFile ("trial.xml");
xml_document<> doc;
xml_node<>* decl = doc.allocate_node(node_declaration);
decl->append_attribute(doc.allocate_attribute("version", "1.0"));
decl->append_attribute(doc.allocate_attribute("encoding", "UTF-8"));
doc.append_node(decl);
xml_node<>* root = doc.allocate_node(node_element, "page");
root->append_attribute(doc.allocate_attribute("xmlns", "http://ALTEC-Center.org/xsd/ocr-annotation-1-0.xsd"));
root->append_attribute(doc.allocate_attribute("Number of lines", "10"));
doc.append_node(root);
for (int i = 0; i < 8; i++)
{
//char buf1[8];
//std::sprintf(buf1, "%d", i);
xml_node<>* child = doc.allocate_node(node_element, "line");
char * idxStr = doc.allocate_string("gvs");
child->append_attribute(doc.allocate_attribute("Index",idxStr));
root->append_node(child);
for (int j = 0; j < 8; j++)
{
xml_node<>* child1 = doc.allocate_node(node_element, "word");
child1->append_attribute(doc.allocate_attribute("Index","asdvs"));
child1->append_attribute(doc.allocate_attribute("x","0.0"));
child1->append_attribute(doc.allocate_attribute("y","0.1"));
child1->append_attribute(doc.allocate_attribute("width","0.2"));
child1->append_attribute(doc.allocate_attribute("hight","0.3"));
child1->append_attribute(doc.allocate_attribute("word","محمد"));
child->append_node(child1);
}
}
theFile << doc;
theFile.close();
doc.clear();
return 0;
}
/在运行代码时,我收到以下错误:"print_children"未在此范围内声明,并且在实例化时通过依赖于参数的查找找不到声明 [-fpermissive]|/
这
看起来像是rapidxml 1.13
中的一个错误。这是错误条目:
https://sourceforge.net/p/rapidxml/bugs/16/
当它工作GCC
时,它在2011
中标记为clang++
。可能是较新版本的GCC
以与过去相同的方式中断clang++
:
print_node(( 是指尚未定义的其他方法(它们在下面立即定义(。我通过将 print_node(( 的 impl 移到它的兄弟 print_children((、print_element_node(( 等下方来解决这个问题,并在顶部放置一个 print_node(( 的前向 decl 来解决这个问题。附上我的差异。差异中的转速数字来自我的 vcs。
Clang似乎比gcc更挑剔的语言规则,我更喜欢这样,FWIW。
也许GCC
和其他编译器现在"对语言规则挑剔"足以发现这个错误?
相关文章:
- 写入向量<向量<bool>>
- Cppcheck生成xml转储文件
- 如何将内容数组写入文本文件?
- 写入位置0x0000000C时发生访问冲突
- 使用ios:ate写入到流会覆盖现有文件
- 独立读取-修改-写入顺序
- 为什么在某些情况下不写入此文件?
- 用C++将哈希表写入文件并从文件中恢复
- std::当在256字节边界上写入整数时,流的奇怪行为
- 为什么指针不写入类的地址?
- Qt 写入 xml: QIODevice::write (QFile, "D:/logs.xml" ): 设备未打开
- C++/RapidXML:编辑节点并写入新的 XML 文件没有更新的节点
- 如何在XML文件中写入,而不要从问号C 开始
- 提升写入 XML 错误编码
- 在 C++ 中使用 RapidXML 写入 XML 文件
- 如何强制 gtest 从 Init 将报告写入 xml
- 如何将已写入 xml 文件的 OpenCV 垫子转换回图像
- 如何将数据写入opencv文件夹中的xml文件
- 使用c++读取,搜索和写入XML
- OpenCV写入XML错误——节点重复