好吧,我在 C++ 中使用 PugiXML 使用 Visual Studio 2010 来获取元素的内容,但问题是当它看到“<”时它停止获取值,所以它没有得到值,它只是得到即使“<”没有关闭其元素,内容也会到达“<”字符。我希望它到达结束标签,即使它忽略标签,但至少只忽略内部标签内的文本。
而且我还想知道如何获取外部 XML,例如,如果我获取元素
pugi::xpath_node_set 工具 = doc.select_nodes("/mesh/bounds/b"); 我该怎么做才能获得“ Link Till here”的全部内容
此内容与此处给出的内容相同:
#include "pugixml.hpp"
#include <iostream>
#include <conio.h>
#include <stdio.h>
using namespace std;
int main//21
() {
string source = "<mesh name='sphere'><bounds><b id='hey'> <a DeriveCaptionFrom='lastparam' name='testx' href='http://www.google.com'>Link Till here<b>it will stop here and ignore the rest</b> text</a></b> 0 1 1</bounds></mesh>";
int from_string;
from_string = 1;
pugi::xml_document doc;
pugi::xml_parse_result result;
string filename = "xgconsole.xml";
result = doc.load_buffer(source.c_str(), source.size());
/* result = doc.load_file(filename.c_str());
if(!result){
cout << "File " << filename.c_str() << " couldn't be found" << endl;
_getch();
return 0;
} */
pugi::xpath_node_set tools = doc.select_nodes("/mesh/bounds/b/a[@href='http://www.google.com' and @DeriveCaptionFrom='lastparam']");
for (pugi::xpath_node_set::const_iterator it = tools.begin(); it != tools.end(); ++it) {
pugi::xpath_node node = *it;
std::cout << "Attribute Href: " << node.node().attribute("href").value() << endl;
std::cout << "Value: " << node.node().child_value() << endl;
std::cout << "Name: " << node.node().name() << endl;
}
_getch();
return 0;
}
这是输出:
Attribute Href: http://www.google.com
Value: Link Till here
Name: a
我希望我足够清楚,在此先感谢