6.6.2. Loading XML

After this XML file has been generated, the easy way to rebuild your scene is to import the information provided by the XML file using the loadFromXML(“fileName”) method. Your code can be as short as the following:

Example 6.5. A simple example using an XML description file

int
main(int argc, char **argv)
{
// Initialize Inventor. This returns a main window to use.
// If unsuccessful, exit.
Widget mainWindow = SoXt::init(argv[0]);    // pass the app name
  if (mainWindow == NULL) exit(1);

// Initialize TerrainViz
  SoTViz::init();

  SoXtExaminerViewer *mainViewer = new SoXtExaminerViewer(mainWindow);
  SoSeparator *mainRoot = new SoSeparator;

  mainViewer->setSceneGraph(mainRoot);

  SoTVizRender *dtmRender = new SoTVizRender();

  mainRoot->addChild(dtmRender);

  dtmRender->loadFromXML("data/africa.xml");

  dtmRender->maxRenderedTriangles = 10000;

// Display main window
  mainViewer->show(); mainViewer->viewAll(); SoXt::show(mainWindow);
  SoXt::mainLoop();  // Main Inventor event loop 
return 0;
}