Want more features on Pastebin? Sign Up, it's FREE!
Guest

RapidXML example

By: a guest on Dec 31st, 2010  |  syntax: C++  |  size: 0.90 KB  |  views: 3,781  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <rapidxml/rapidxml.hpp>
  2. #include <fstream>
  3. #include <iostream>
  4.  
  5. ...
  6.  
  7.     {
  8.         using namespace rapidxml;
  9.         using namespace std;
  10.  
  11.         ifstream fin("data/cards/meta/1.xml");
  12.         if (fin.fail()) return 1;
  13.  
  14.         fin.seekg(0, ios::end);
  15.         size_t length = fin.tellg();
  16.         fin.seekg(0, ios::beg);
  17.         char* buffer = new char[length + 1];
  18.         fin.read(buffer, length);
  19.         buffer[length] = '\0';
  20.  
  21.         fin.close();
  22.  
  23.         xml_document<> doc;
  24.         doc.parse<0>(buffer);
  25.  
  26.         delete [] buffer;
  27.  
  28.         cout << "The first node is '" << doc.first_node()->name() << "'\n";
  29.         for (xml_node<>* n = doc.first_node("card")->first_node(); n;
  30.             n = n->next_sibling())
  31.         {
  32.             char* v = n->value();
  33.             if (!v || !*v) v = "(empty)";
  34.             cout << n->name() << " : " << v << '\n';
  35.         }
  36.     }
clone this paste RAW Paste Data