我正在尝试加载"tree.xml“,它和loadfile.cpp在同一个目录中,也有pugixml.cpp,pugixml.hpp,pugiconfig.hpp。
#include "pugixml.cpp"
#include <iostream>
using namespace std;
int main()
{
pugi::xml_document doc;
pugi::xml_parse_result result = doc.load_file("tree.xml");
if (doc.load_file("file.xml")){
cout << "success" << endl;
}else{
cout << "fail" << endl;
}
cout << "Load result: " << result.description() << ", mesh name: " << doc.child("mesh").attribute("name").value() << endl;
}我得到的结果是:
fail
Load result: No error, mesh name: 我在这里遵循手册:“加载Documnet”下的http://cdn.rawgit.com/zeux/pugixml/v1.4/docs/quickstart.html。
tree.xml文档如下所示:
<bookstore>
<book category="COOKING">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
</book>
<book category="CHILDREN">
<title lang="en">Harry Potter</title>
<author>J K. Rowling</author>
<year>2005</year>
<price>29.99</price>
</book>
<book category="WEB">
<title lang="en">Learning XML</title>
<author>Erik T. Ray</author>
<year>2003</year>
<price>39.95</price>
</book>
</bookstore>为什么没有加载文件?我不知道哪里不对劲。
发布于 2014-11-09 08:37:27
不要紧。我找到了一个解决方案。
#include "pugixml.cpp"
#include <iostream>
using namespace std;
int main()
{
pugi::xml_document doc;
pugi::xml_parse_result result = doc.load_file("tree.xml");
if (result)){ // CHANGE THIS LINE TO RESULT INSTEAD OF doc.load_file("tree.xml")
cout << "success" << endl;
}else{
cout << "fail" << endl;
}
cout << "Load result: " << result.description() << ", mesh name: " << doc.child("mesh").attribute("name").value() << endl;
}https://stackoverflow.com/questions/26823661
复制相似问题