How to read test tables from xml files

Many parameters needed for the configuration of the several tests and of the interfaces are currently being stored in xml file which can be read to fill up the test tables used by the Test Supervisor application. The following piece of code shows how to read the a table stored in the example file Test.xml. This file contains two structures one inside the other. The main structure is defined in the table_ node and contains a string, a flag and a sub-structure defined in the aStructure_ node. This sub-structure contains an array of strings and a number. To define the "store" for this data one can proceed the following way:

1) Define the sub-structure by the following bag:

class Structure {
public:
   void registerFields(xdata::Bag<Structure> *bag){
      bag->addField("anArray_",&Array_);  
      bag->addField("aNumber_",&Number_);  
    }

    xdata::Vector<xdata::String > Array_;
    xdata::UnsignedLong Number_;
};

2) Define the table as the top structure that holds the Structure you defined before:

class Table {
public:
   void registerFields(xdata::Bag<Structure> *bag){
      bag->addField("aString_",&String_);  
      bag->addField("aFlag_",&Flag_);  
      bag->addField("aStructure_",&Structure_);  
    }

    xdata::String  String_;
    xdata::Boolean Flag_;
    xdata::Bag<Structure> Structure_;
};

3) Use the IntegrationTests::BagUtils to fill the Table structure from the file:

  //instantiate a new table
  xdata::Bag<Table> myTable_;

  //define path to table file
  string pathToTableFile_("/myPath/.../Test.xml");

  try{
     //parse table from file
     IntegrationTests::BagUtils::readTableFromFile(&myTable_,pathToTableFile_);
   }
   catch(IntegrationTests::exception::Exception &ite_){
     ... handle exception ...
   }

And the table is filled correctly and can be used from this point forward. The converse method (writeTableToAFile) is also implemented in the referred namespace.

-- PedroSilva - 24 Aug 2006

Topic attachments
I Attachment History Action Size Date Who Comment
XMLxml Test.xml r2 r1 manage 0.9 K 2006-08-24 - 23:44 PedroSilva  
Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r3 - 2006-11-24 - PedroSilva
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    Main All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright &© 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
or Ideas, requests, problems regarding TWiki? use Discourse or Send feedback