1 // file : examples/persistence/driver.cxx 2 // copyright : not copyrighted - public domain 3 4 #include <fstream> 5 #include <iostream> 6 7 #include <libstudxml/parser.hxx> 8 #include <libstudxml/serializer.hxx> 9 10 #include "position.hxx" 11 12 using namespace std; 13 14 int main(int argc,char * argv[])15main (int argc, char* argv[]) 16 { 17 if (argc != 2) 18 { 19 cerr << "usage: " << argv[0] << " <xml-file>" << endl; 20 return 1; 21 } 22 23 try 24 { 25 // Load the object model state from XML. 26 // 27 ifstream ifs (argv[1]); 28 xml::parser p (ifs, argv[1]); 29 30 object o (p); 31 32 // Save the object model state back to XML. 33 // 34 xml::serializer s (cout, "output"); 35 36 o.serialize (s); 37 } 38 // This handler will handle both parsing (xml::parsing) and serialization 39 // (xml::serialization) exceptions. 40 // 41 catch (const xml::exception& e) 42 { 43 cerr << e.what () << endl; 44 return 1; 45 } 46 } 47