Visual Studio2010を使用してC++でPugiXMLを使用して要素のコンテンツを取得していますが、「<」が表示されると値の取得が停止するため、値は取得されません。 「<」が要素を閉じていなくても、「<」文字に達するまでのコンテンツ。タグを無視しても、終了タグに到達するまで取得したいのですが、少なくとも内部タグ内のテキストのみです。
また、たとえば要素をフェッチした場合に外部XMLを取得する方法も知りたいです。
pugi :: xpath_node_set tools = doc.select_nodes( "/ mesh / bounds / b"); 「ここまでリンク」というコンテンツ全体を取得するにはどうすればよいですか
この内容はここで与えられたものと同じです:
#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
私は十分に明確だったと思います、事前に感謝します