Changeset 154

Show
Ignore:
Timestamp:
07/04/08 10:53:14 (6 months ago)
Author:
zork
Message:

namespace support for streams and element order for XMLOstream

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dba/dba.bkl

    r151 r154  
    199199      dba/xmlistream.cpp 
    200200      dba/xmlostream.cpp 
     201      dba/xmlutils.cpp 
    201202    </sources> 
    202203        <msvc-headers> 
     
    206207      dba/xmlistream.h 
    207208      dba/xmlostream.h 
     209      dba/xmlutils.h 
    208210          </msvc-headers> 
    209211  </template> 
  • trunk/dba/dba/xmlarchive.cpp

    r153 r154  
    5555  } else { 
    5656    mDocument = xmlNewDoc((const xmlChar*)"1.0"); 
     57    xmlNodePtr node; 
    5758    if (mRootNodeName != NULL) { 
    58       xmlNodePtr node = xmlNewDocNode(mDocument,NULL,mRootNodeName,NULL); 
    59       xmlDocSetRootElement(mDocument,node); 
     59      node = xmlNewDocNode(mDocument,NULL,mRootNodeName,NULL); 
     60    } else { 
     61      node = xmlNewDocNode(mDocument,NULL,(xmlChar*)"__dba_for_replace",NULL); 
    6062    }; 
     63    xmlDocSetRootElement(mDocument,node); 
    6164  }; 
    6265  updateEncoding(); 
    63   if (mRootNodeName != NULL) { 
    64     mRootNode = mDocument->children; 
    65   } else { 
    66     mRootNode = xmlDocGetRootElement(mDocument); 
    67   }; 
     66  mRootNode = xmlDocGetRootElement(mDocument); 
     67}; 
     68 
     69void  
     70XMLArchive::addNamespace(const char* pName, const char* pPrefix) { 
     71  if (!isOpen()) 
     72    throw APIException("XMLArchive must be open to add namespace to it"); 
     73  xmlNsPtr ret = xmlNewNs(mRootNode, (xmlChar*)pName, (xmlChar*)pPrefix); 
     74  if (ret == NULL) 
     75    throw XMLException("Failed to add namespace to archive"); 
    6876}; 
    6977 
     
    8290  if (mRootNodeName != NULL) 
    8391    root = root->children; 
    84   return new XMLIStream(root,mConvSpecs); 
     92  return new XMLIStream(mDocument,root,mConvSpecs); 
    8593}; 
    8694 
    8795OStream*  
    8896XMLArchive::getOutputStream() { 
    89   return new XMLOStream(mDocument,mRootNode,mConvSpecs); 
     97  return new XMLOStream(mDocument,mRootNode,mRootNodeName != NULL,mConvSpecs); 
    9098}; 
    9199 
     
    95103  if (mRootNodeName != NULL) 
    96104    root = root->children; 
    97   return XMLIStream(root,mConvSpecs); 
     105  return XMLIStream(mDocument,root,mConvSpecs); 
    98106}; 
    99107 
    100108XMLOStream  
    101109XMLArchive::getOStream() { 
    102   XMLOStream ret(mDocument,mRootNode,mConvSpecs); 
     110  XMLOStream ret(mDocument,mRootNode,mRootNodeName == NULL,mConvSpecs); 
    103111  return ret; 
    104112}; 
  • trunk/dba/dba/xmlarchive.h

    r150 r154  
    1818#include "xmlerrorhandler.h" 
    1919#include <libxml/tree.h> 
     20#include <list> 
    2021 
    2122namespace dba { 
     
    2728  public: 
    2829    XMLArchive(); 
     30    /** 
     31      Set name of root node. If set to NULL then it is possible to IStream::get  
     32      only one object from archive file pointed by root element,  
     33      otherwise archive will try to get list of objects from subelement of root  
     34      element in xml file 
     35      @param pName name of root object or NULL if elements from second level should be retrieved 
     36    */ 
    2937    void setRootNodeName(const char* pName); 
     38    /** 
     39      Add namespace to document. You have to call this method 
     40      if there are namespace prefixed members in class store table 
     41    */ 
     42    void addNamespace(const char* pName, const char* pPrefix); 
    3043    virtual void open(const char* pOpenStr); 
    3144    /** 
     
    3346    */ 
    3447    void close(); 
    35     virtual bool isOpen() const { return mRootNode != NULL; } 
     48    virtual bool isOpen() const { return mDocument != NULL; } 
    3649    XMLOStream getOStream(); 
    3750    XMLIStream getIStream(); 
  • trunk/dba/dba/xmlistream.cpp

    r153 r154  
    1111// 
    1212#include "xmlistream.h" 
     13#include "xmlutils.h" 
    1314#include "collectionfilter.h" 
    1415#include <iostream> 
     
    1617namespace dba { 
    1718 
    18 XMLIStream::XMLIStream(xmlNodePtr pNode, const ConvSpec& pSpecs) 
     19XMLIStream::XMLIStream(xmlDocPtr pDocument, xmlNodePtr pNode, const ConvSpec& pSpecs) 
    1920  : IStream(), 
    2021    ConvSpecContainer(pSpecs), 
    21     mParentNode(pNode) 
     22    mDocument(pDocument), 
     23    mParentNode(pNode), 
     24    mIgnoreNonMappedNodes(false), 
     25    mIgnoreOrder(false) 
    2226{ 
    2327  mCurrentNode = findNonTextNode(mParentNode); 
     
    158162}; 
    159163 
     164xmlAttrPtr 
     165XMLIStream::findAttribute(xmlNodePtr pNode, const char* pMemberName) { 
     166  char* ns = XMLUtils::getNsFromName(pMemberName); 
     167 
     168  xmlAttrPtr ret = NULL; 
     169  if (ns != NULL) { 
     170    xmlNsPtr nsptr = xmlSearchNs(mDocument,pNode,(xmlChar*)ns); 
     171    if (nsptr == NULL) { 
     172      std::string err("Error loading data from node '"); 
     173      err += pMemberName; 
     174      err += "'. Namespace not added, call addNamespace on XMLArchive first"; 
     175      throw APIException(err.c_str()); 
     176    }; 
     177    char* name = XMLUtils::getNameWithoutNs(pMemberName); 
     178    ret = xmlHasNsProp(pNode,(xmlChar*)name,nsptr->href); 
     179    delete [] name; 
     180  } else { 
     181    ret = xmlHasProp(pNode,(xmlChar*)pMemberName); 
     182  }; 
     183  delete [] ns; 
     184  return ret; 
     185}; 
     186 
    160187void 
    161188XMLIStream::applyFilters(Storeable* pObject) { 
     
    171198      dba::StoreableFilterBase* filter(member->getFilter()); 
    172199      setFilterPtr(*filter,(char*)pObject + (int)(member->getMemberOffset() + tbl->getClassOffset())); 
    173       xmlAttrPtr attr = xmlHasProp(mCurrentNode, (xmlChar*)member->getMemberName()); 
     200      xmlAttrPtr attr = findAttribute(mCurrentNode,member->getMemberName()); 
    174201      if (attr != NULL) { 
    175202        xmlChar* xmldata = xmlNodeGetContent(attr->children); 
     
    205232  for(VarMap::iterator it = mBindings.begin(); it != mBindings.end(); it++) { 
    206233    if (!xmlStrcmp((xmlChar*)(it->mTable), mCurrentNode->name)) { 
    207       xmlAttrPtr attr = xmlHasProp(mCurrentNode, (xmlChar*)it->mField); 
     234      xmlAttrPtr attr = findAttribute(mCurrentNode, it->mField); 
    208235      dba::StoreableFilterBase& filter(*(it->mFilter)); 
    209236      if (attr != NULL) { 
  • trunk/dba/dba/xmlistream.h

    r139 r154  
    2424class XMLIStream : public IStream, public XMLErrorHandler, public ConvSpecContainer { 
    2525  public: 
    26     XMLIStream(xmlNodePtr pNode, const ConvSpec& pSpecs); 
     26    XMLIStream(xmlDocPtr pDocument, xmlNodePtr pNode, const ConvSpec& pSpecs); 
     27    /** 
     28      If set to true, then stream will igore all nodes that are not mapped to class 
     29      members or binded to variables. Default value is false. 
     30    */ 
     31    void ignoreNonMappedNodes(bool pFlag); 
     32    /** 
     33      If set to true, then stream will igore order of readed elements and try to  
     34      find element using its name among all elements on single level. Otherwise 
     35      element order in xml file has to be the same as store table layout. Elements 
     36      from parent store table should be placed before elements in child store table. 
     37      Default value is false. 
     38    */ 
     39    void ignoreNodeOrder(bool pFlag); 
    2740    virtual void close(); 
    2841    virtual void destroy(); 
     
    3447    virtual ~XMLIStream(); 
    3548  private: 
     49    xmlDocPtr mDocument; 
    3650    xmlNodePtr mParentNode; 
    3751    xmlNodePtr mCurrentNode; 
     52    bool mIgnoreNonMappedNodes; 
     53    bool mIgnoreOrder; 
    3854     
    3955    virtual void setIdsCondition(const char* pFKeyName, id pRelationId, const std::vector<id>& pIds); 
     
    4561    bool isClassMember(Storeable* pObject, xmlNodePtr pNode); 
    4662    void getChildren(Storeable* pParent, xmlNodePtr pNode); 
     63    xmlAttrPtr findAttribute(xmlNodePtr pNode, const char* pMemberName); 
    4764}; 
    4865 
  • trunk/dba/dba/xmlostream.cpp

    r153 r154  
    1313#include "conversion.h" 
    1414#include "collectionfilter.h" 
     15#include "xmlutils.h" 
    1516 
    1617namespace dba { 
    1718 
    18 XMLOStream::XMLOStream(xmlDocPtr pDocument, xmlNodePtr pNode, const ConvSpec& pSpecs) 
     19XMLOStream::XMLOStream(xmlDocPtr pDocument, xmlNodePtr pNode, bool pReplaceParentNode, const ConvSpec& pSpecs) 
    1920  : OStream(), 
    2021    ConvSpecContainer(pSpecs), 
    2122    mDocument(pDocument), 
    22     mParentNode(pNode) 
     23    mParentNode(pNode), 
     24    mReplaceParentNode(pReplaceParentNode) 
    2325{ 
    2426} 
     
    4951  //file is always created from scratch 
    5052  return store(pObject); 
     53}; 
     54 
     55void 
     56XMLOStream::setAttribute(xmlNodePtr pNode, const char* pName, const xmlChar* pData) { 
     57  char* nsname(XMLUtils::getNsFromName(pName)); 
     58  if (nsname == NULL) { 
     59    xmlNewProp(pNode,(xmlChar*)pName,pData); 
     60  } else { 
     61    xmlNsPtr ns = xmlSearchNs(mDocument,pNode,(xmlChar*)nsname); 
     62    delete [] nsname; 
     63    if (ns == NULL) { 
     64      std::string err("Error setting attribute '"); 
     65      err += pName; 
     66      err += "'. Namespace not added, call addNamespace on XMLArchive first"; 
     67      throw APIException(err.c_str()); 
     68    }; 
     69    char* propname(XMLUtils::getNameWithoutNs(pName)); 
     70    xmlNewNsProp(pNode,ns,(xmlChar*)propname,pData); 
     71    delete [] propname; 
     72  }; 
     73}; 
     74 
     75xmlNodePtr 
     76XMLOStream::createNode(const char* pName) { 
     77  char* nsname(XMLUtils::getNsFromName(pName)); 
     78  xmlNsPtr ns = NULL; 
     79  xmlNodePtr node = NULL; 
     80  if (nsname != NULL) { 
     81    ns = xmlSearchNs(mDocument,mParentNode,(xmlChar*)nsname); 
     82    delete [] nsname; 
     83    if (ns == NULL) { 
     84      std::string err("Error creating node '"); 
     85      err += pName; 
     86      err += "'. Namespace not added, call addNamespace on XMLArchive first"; 
     87      throw APIException(err.c_str()); 
     88    }; 
     89    char* nodename(XMLUtils::getNameWithoutNs(pName)); 
     90    node = xmlNewNode(ns, (xmlChar*)nodename); 
     91    delete [] nodename; 
     92  } else { 
     93    node = xmlNewNode(ns, (xmlChar*)pName); 
     94  }; 
     95  return node; 
    5196}; 
    5297 
     
    60105    if (!filter.isNull()) { 
    61106      std::string strdata(filter.toString(getConversionSpecs())); 
    62       xmlNewProp(pNode,(xmlChar*)member->name,(xmlChar*)strdata.c_str()); 
     107      setAttribute(pNode,member->name,(xmlChar*)strdata.c_str()); 
    63108    }; 
    64109    member = member->next; 
     
    76121      data = filter.toString(mConvSpecs); 
    77122      if (!data.empty()) { 
    78         xmlNewProp(pNode,(xmlChar*)it->mField,(xmlChar*)data.c_str()); 
     123        setAttribute(pNode,it->mField,(xmlChar*)data.c_str()); 
    79124      }; 
    80125    }; 
     
    89134 
    90135  mt_class* current = mMemberList->mFirst; 
    91   xmlNodePtr node = xmlNewNode(NULL, (xmlChar*)current->name); 
     136  xmlNodePtr node = createNode(current->name); 
     137  if (!mReplaceParentNode) { 
     138    //store table is readed from last element to first 
     139    //and from child table to parent. 
     140    //but we want to add elements in oposite order 
     141    xmlNodePtr last = xmlGetLastChild(mParentNode); 
     142    if (last == NULL) 
     143      xmlAddChild(mParentNode, node); 
     144    else 
     145      xmlAddPrevSibling(last,node); 
     146  } else { 
     147    node->nsDef = xmlCopyNamespaceList(mParentNode->nsDef); 
     148    xmlFree(xmlDocSetRootElement(mDocument,node)); 
     149    mReplaceParentNode = false; 
     150  }; 
    92151  //FIXME add configuration for storing id? 
    93152  //xmlNewProp(node,(xmlChar*)"id",(xmlChar*)(toStr(id).c_str())); 
     
    99158      break; 
    100159  }; 
    101   if (mParentNode != NULL) 
    102     xmlAddChild(mParentNode, node); 
    103   else 
    104     xmlDocSetRootElement(mDocument,node); 
    105160  return true; 
    106161}; 
     
    144199    if (iterator->hasNext()) { 
    145200      if (pMember.getFKeyName() != NULL) { 
    146         xmlAddChild(mParentNode, xmlNewNode(NULL, (xmlChar*)pMember.getFKeyName())); 
     201        xmlAddChild(mParentNode, createNode(pMember.getFKeyName())); 
    147202        mParentNode = mParentNode->children; 
    148203      }; 
  • trunk/dba/dba/xmlostream.h

    r153 r154  
    2424class XMLOStream  : public OStream, public XMLErrorHandler, public ConvSpecContainer { 
    2525  public: 
    26     XMLOStream(xmlDocPtr pDocument, xmlNodePtr pNode, const ConvSpec& pSpecs); 
     26    XMLOStream(xmlDocPtr pDocument, xmlNodePtr pNode, bool pReplaceParentNode, const ConvSpec& pSpecs); 
    2727    virtual void close(); 
    2828    virtual void destroy(); 
     
    4545    xmlDocPtr mDocument; 
    4646    xmlNodePtr mParentNode; 
     47    bool mReplaceParentNode; 
    4748     
    4849    void updateNodeFromVars(xmlNodePtr pNode, mt_class* pTable); 
    4950    void updateNodeFromObject(xmlNodePtr pNode, const Storeable& pObject, mt_class* pTable); 
     51    void setAttribute(xmlNodePtr pNode, const char* pName, const xmlChar* pData); 
     52    xmlNodePtr createNode(const char* pName); 
    5053}; 
    5154 
  • trunk/dba/test/main.cpp

    r153 r154  
    150150  //runner.addTest(new CppUnit::TestCaller<dba_tests::CSVTestCase>("debug_test",&dba_tests::CSVTestCase::manual)); 
    151151  //runner.addTest(new CppUnit::TestCaller<SQLite3SQLArchiveTestCase>("debug_test",&SQLite3SQLArchiveTestCase::transactions_rollback)); 
    152   runner.addTest(dba_tests::XMLTestCase::suite()); 
    153   //runner.addTest(new CppUnit::TestCaller<dba_tests::XMLTestCase>("debug_test",&dba_tests::XMLTestCase::simpleOneLoad)); 
     152  //runner.addTest(dba_tests::XMLTestCase::suite()); 
     153  runner.addTest(new CppUnit::TestCaller<dba_tests::XMLTestCase>("debug_test",&dba_tests::XMLTestCase::load_two_inverted)); 
     154  //runner.addTest(new CppUnit::TestCaller<dba_tests::XMLTestCase>("debug_test",&dba_tests::XMLTestCase::store_two)); 
    154155  //runner.addTest(new CppUnit::TestCaller<OdbcPluginTestCase>("debug_test",&OdbcPluginTestCase::dbConnection)); 
    155156  //runner.addTest(new CppUnit::TestCaller<PostgresSQLArchiveTestCase>("debug_test",&PostgresSQLArchiveTestCase::sqlError)); 
  • trunk/dba/test/testobject.cpp

    r139 r154  
    122122END_STORE_TABLE() 
    123123 
    124 
     124} //namespace 
     125 
  • trunk/dba/test/testobject.h

    r141 r154  
    605605}; 
    606606 
    607 } 
     607} //namespace 
    608608 
    609609#endif 
  • trunk/dba/test/xmltestcase.cpp

    r153 r154  
    1616#include "dba/string_filter.h" 
    1717#include "dba/stdlist.h" 
     18#include "dba/single.h" 
    1819 
    1920#include <fstream> 
     
    531532}; 
    532533 
     534class NsObject: public dba::Storeable { 
     535  DECLARE_STORE_TABLE(); 
     536public: 
     537  NsObject() { } 
     538  NsObject(const std::string& pNsName) 
     539    : mNsName(pNsName) 
     540  { 
     541  } 
     542  virtual bool operator ==(const NsObject& pNsObject) const { 
     543    return (mNsName == pNsObject.mNsName); 
     544  } 
     545  std::string mNsName; 
     546}; 
     547 
     548BEGIN_STORE_TABLE(NsObject, dba::Storeable, "nsobject") 
     549  BIND_STR(NsObject::mNsName, dba::String , "ns:name") 
     550END_STORE_TABLE(); 
     551 
     552void 
     553XMLTestCase::load_missing_ns() { 
     554  const char* nsdata =  
     555"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" 
     556" <nsobject name=\"test\" ns:name=\"namespace\">\n" 
     557" </nsobject>\n"; 
     558  { 
     559    std::ofstream file("ns_missing.xml"); 
     560    file << nsdata; 
     561  }; 
     562  { 
     563    dba::XMLArchive xmlArch; 
     564    xmlArch.setRootNodeName("nsobject"); 
     565    xmlArch.open("ns_missing.xml"); 
     566    NsObject loaded; 
     567    dba::XMLIStream stream(xmlArch.getIStream()); 
     568    try { 
     569      stream.get(&loaded); 
     570    } catch (const dba::APIException& pEx) { 
     571    }; 
     572  }; 
     573} 
     574 
     575void 
     576XMLTestCase::load_ns_single() { 
     577  const char* nsdata =  
     578"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" 
     579" <nsobject xmlns:ns='http://bogus_ns_namespace' ns:name=\"namespace\" />\n" 
     580; 
     581  { 
     582    std::ofstream file("ns_load.xml"); 
     583    file << nsdata; 
     584  }; 
     585  { 
     586    NsObject expected("namespace"); 
     587 
     588    dba::XMLArchive xmlArch; 
     589    xmlArch.setRootNodeName(NULL); 
     590    xmlArch.open("ns_load.xml"); 
     591    NsObject loaded; 
     592    dba::XMLIStream stream(xmlArch.getIStream()); 
     593    stream.get(&loaded); 
     594    CPPUNIT_ASSERT(loaded == expected); 
     595  }; 
     596} 
     597 
     598void 
     599XMLTestCase::store_ns_single() { 
     600  const char* nsdata =  
     601"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" 
     602"<nsobject xmlns:ns=\"http://bogus_ns_namespace\" ns:name=\"namespace\"/>\n" 
     603; 
     604  { 
     605    dba::XMLArchive xmlArch; 
     606    xmlArch.setRootNodeName(NULL); 
     607    unlink("ns_store.xml"); 
     608    xmlArch.open("ns_store.xml"); 
     609    xmlArch.addNamespace("http://bogus_ns_namespace","ns"); 
     610    NsObject obj("namespace"); 
     611    dba::XMLOStream stream(xmlArch.getOStream()); 
     612    stream.put(&obj); 
     613  }; 
     614  CPPUNIT_ASSERT(compareXML("ns_store.xml",nsdata)); 
     615} 
     616 
     617void 
     618XMLTestCase::load_ns() { 
     619  const char* nsdata =  
     620"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" 
     621"<dba xmlns:ns=\"http://bogus_ns_namespace\">\n" 
     622"  <nsobject ns:name=\"namespace\"/>\n" 
     623"</dba>\n" 
     624; 
     625  { 
     626    std::ofstream file("ns_load.xml"); 
     627    file << nsdata; 
     628  }; 
     629  { 
     630    NsObject expected("namespace"); 
     631 
     632    dba::XMLArchive xmlArch; 
     633    xmlArch.open("ns_load.xml"); 
     634    NsObject loaded; 
     635    dba::XMLIStream stream(xmlArch.getIStream()); 
     636    stream.get(&loaded); 
     637    CPPUNIT_ASSERT(loaded == expected); 
     638  }; 
     639} 
     640 
     641void 
     642XMLTestCase::store_ns() { 
     643  const char* nsdata =  
     644"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" 
     645"<dba xmlns:ns=\"http://bogus_ns_namespace\">\n" 
     646"  <nsobject ns:name=\"namespace\"/>\n" 
     647"</dba>\n" 
     648; 
     649  { 
     650    dba::XMLArchive xmlArch; 
     651    unlink("ns_store.xml"); 
     652    xmlArch.open("ns_store.xml"); 
     653    xmlArch.addNamespace("http://bogus_ns_namespace","ns"); 
     654    NsObject obj("namespace"); 
     655    dba::XMLOStream stream(xmlArch.getOStream()); 
     656    stream.put(&obj); 
     657  }; 
     658  CPPUNIT_ASSERT(compareXML("ns_store.xml",nsdata)); 
     659} 
     660 
     661class TwoSingles : public dba::Storeable { 
     662    DECLARE_STORE_TABLE(); 
     663  public: 
     664    TwoSingles() {}; 
     665    TwoSingles(const char* pName)  
     666      : mName(pName), 
     667        mObj1(TestObject(1,1,"1",Utils::getDate(2008,1,1,0,0,0))), 
     668        mObj2(TestObject(20,20,"20",Utils::getDate(2008,2,2,0,0,0))) 
     669    {}; 
     670    bool operator==(const TwoSingles& pObj) { 
     671      if (mName != pObj.mName) 
     672        return false; 
     673      return mObj1 == pObj.mObj1 && mObj2 == pObj.mObj2; 
     674    }; 
     675    std::string mName; 
     676    TestObject mObj1; 
     677    TestObject mObj2;   
     678}; 
     679 
     680BEGIN_STORE_TABLE(TwoSingles,dba::Storeable,"twosingles") 
     681  BIND_STR(TwoSingles::mName, dba::String, "parent") 
     682  BIND_COL(TwoSingles::mObj1, dba::Single, NULL) 
     683  BIND_COL(TwoSingles::mObj2, dba::Single, NULL) 
     684END_STORE_TABLE() 
     685 
     686void 
     687XMLTestCase::load_two() { 
     688  const char* nsdata =  
     689"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" 
     690"<dba>\n" 
     691"  <twosingles parent=\"parent_name\">\n" 
     692"    <test_objects i_value=\"1\" f_value=\"1\" s_value=\"1\" d_value=\"2008-01-01Z00:00:00\"/>\n" 
     693"    <test_objects i_value=\"20\" f_value=\"20\" s_value=\"20\" d_value=\"2008-02-02Z00:00:00\"/>\n" 
     694"  </twosingles>\n" 
     695"</dba>\n" 
     696; 
     697  { 
     698    std::ofstream file("load_two.xml"); 
     699    file << nsdata; 
     700  }; 
     701  { 
     702    TwoSingles expected("parent_name"); 
     703 
     704    dba::XMLArchive xmlArch; 
     705    xmlArch.open("load_two.xml"); 
     706    TwoSingles loaded; 
     707    dba::XMLIStream stream(xmlArch.getIStream()); 
     708    stream.get(&loaded); 
     709    CPPUNIT_ASSERT(loaded == expected); 
     710  }; 
     711}; 
     712 
     713void 
     714XMLTestCase::store_two() { 
     715  const char* nsdata =  
     716"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" 
     717"<dba>\n" 
     718"  <twosingles parent=\"parent_name\">\n" 
     719"    <test_objects i_value=\"1\" f_value=\"1\" s_value=\"1\" d_value=\"2008-01-01Z00:00:00\"/>\n" 
     720"    <test_objects i_value=\"20\" f_value=\"20\" s_value=\"20\" d_value=\"2008-02-02Z00:00:00\"/>\n" 
     721"  </twosingles>\n" 
     722"</dba>\n" 
     723; 
     724  { 
     725    dba::XMLArchive xmlArch; 
     726    unlink("store_two.xml"); 
     727    xmlArch.open("store_two.xml"); 
     728    TwoSingles obj("parent_name"); 
     729    dba::XMLOStream stream(xmlArch.getOStream()); 
     730    stream.put(&obj); 
     731  }; 
     732  CPPUNIT_ASSERT(compareXML("store_two.xml",nsdata)); 
     733} 
     734 
     735void 
     736XMLTestCase::load_two_inverted() { 
     737  const char* nsdata =  
     738"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" 
     739"<dba>\n" 
     740"  <twosingles parent=\"parent_name\">\n" 
     741"    <test_objects i_value=\"20\" f_value=\"20\" s_value=\"20\" d_value=\"2008-02-02Z00:00:00\"/>\n" 
     742"    <test_objects i_value=\"1\" f_value=\"1\" s_value=\"1\" d_value=\"2008-01-01Z00:00:00\"/>\n" 
     743"  </twosingles>\n" 
     744"</dba>\n" 
     745; 
     746  { 
     747    std::ofstream file("load_two_inverted.xml"); 
     748    file << nsdata; 
     749  }; 
     750  { 
     751    TwoSingles expected("parent_name"); 
     752 
     753    dba::XMLArchive xmlArch; 
     754    xmlArch.open("load_two_inverted.xml"); 
     755    TwoSingles loaded; 
     756    dba::XMLIStream stream(xmlArch.getIStream()); 
     757    stream.get(&loaded); 
     758    CPPUNIT_ASSERT(loaded == expected); 
     759  }; 
     760}; 
     761 
    533762 
    534763} //namespace 
  • trunk/dba/test/xmltestcase.h

    r153 r154  
    4545      CPPUNIT_TEST(sublist_tree_load); 
    4646      CPPUNIT_TEST(sublist_three_simple_load); 
     47      CPPUNIT_TEST(load_missing_ns); 
     48      CPPUNIT_TEST(load_ns_single); 
     49      CPPUNIT_TEST(store_ns_single); 
     50      CPPUNIT_TEST(load_ns); 
     51      CPPUNIT_TEST(store_ns); 
     52      CPPUNIT_TEST(load_two); 
    4753    CPPUNIT_TEST_SUITE_END(); 
    4854  public: 
     
    7177    void sublist_tree_load(); 
    7278    void sublist_three_simple_load(); 
     79    void load_missing_ns(); 
     80    void load_ns_single(); 
     81    void store_ns_single(); 
     82    void load_ns(); 
     83    void store_ns(); 
     84    void load_two(); 
     85    void load_two_inverted(); 
     86    void store_two(); 
    7387  private: 
    7488    bool compareXML(const char* pFilename, const char* pData); 
  • trunk/presets/syslibs.bkl

    r151 r154  
    2121  <if cond="FORMAT=='autoconf'"> 
    2222    <cxxflags>$(xml2_CXXFLAGS)</cxxflags> 
    23     <cxxflags>$(xslt_CXXFLAGS)</cxxflags> 
    2423  </if> 
    2524</template> 
     
    2928    <if cond="TOOLSET=='win32'"> 
    3029      <sys-lib>libxml2</sys-lib> 
    31       <sys-lib>libexslt</sys-lib> 
    32       <sys-lib>libxslt</sys-lib> 
    3330    </if> 
    3431  </if> 
    3532  <if cond="FORMAT=='autoconf'"> 
    3633    <ldlibs>$(xml2_LIBS)</ldlibs> 
    37     <ldlibs>$(xslt_LIBS)</ldlibs> 
    3834  </if> 
    3935</template>