LINUX.ORG.RU

libxml node value


0

0

Здравствуйте!

Не подскажете, в чем может быть ошибка. Node по xpath находит нормально, возвращает его имя нормально. Как теперь получит значение node-а? Я попробывал через ContentNode, но получаю Segmentation fault. Заранее спасибо.

----------output tag3 /tag1/tag2/tag3 Segmentation fault ----------output end

----------source #include <libxml++/libxml++.h> #include <iostream>

using std::string; using std::cout; using std::endl; using std::cin;

using namespace xmlpp;

int main() { DomParser parser("d.xml"); Document *doc = parser.get_document(); Element *rootElem = doc->get_root_node(); NodeSet set = rootElem->find("/tag1/tag2/tag3"); Node *node = *set.begin(); cout << node->get_name() << endl; cout << node->get_path() << endl;

ContentNode content(node->cobj());

// cout << content.get_content() << endl; // cout << content.is_white_space() << endl;

return 0; } ----------source end

anonymous

Ответ на: комментарий от anonymous

----------output
tag3
/tag1/tag2/tag3
Segmentation fault
----------output end

----------source
#include <libxml++/libxml++.h>
#include <iostream>

using std::string;
using std::cout;
using std::endl;
using std::cin;

using namespace xmlpp;

int main()
{
DomParser parser("d.xml");
Document *doc = parser.get_document();
Element *rootElem = doc->get_root_node();
NodeSet set = rootElem->find("/tag1/tag2/tag3");
Node *node = *set.begin();
cout << node->get_name() << endl;
cout << node->get_path() << endl;

ContentNode content(node->cobj());

// cout << content.get_content() << endl;
// cout << content.is_white_space() << endl;

return 0;
}
----------source end

anonymous
()
Ответ на: комментарий от anonymous

на сколько я помню у той ноды что ты получил возми потомков но получится один и будет соотвествовать типу TextNode у него и бери значение

satellite13
()
Ответ на: комментарий от anonymous

xmlpp::Node::NodeList list = node->get_children(); for(xmlpp::Node::NodeList::iterator iter = list.begin(); iter != list.end(); ++iter) { print_node(*iter); }

void print_node(const xmlpp::Node* node) { const xmlpp::TextNode* nodeText = dynamic_cast<const xmlpp::TextNode*>(node);

if(nodeText) { std::cout << "text = \"" << nodeText->get_content() << "\"" << std::endl; } }

satellite13
()
Ответ на: комментарий от satellite13

Огромное спасибо. Все отработало как часы.

anonymous
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.