Changeset 172

Show
Ignore:
Timestamp:
07/29/08 15:26:33 (4 months ago)
Author:
zork
Message:

added possibility to create archive from xmlDocPtr

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/dba/dba/xmlarchive.cpp

    r166 r172  
    3131  xmlFree(mRootNodeName); 
    3232  mRootNodeName = xmlStrdup((xmlChar*)pName); 
     33}; 
     34 
     35void 
     36XMLArchive::open(xmlDocPtr pDocument) { 
     37  mDocument = pDocument; 
     38  xmlNodePtr root = xmlDocGetRootElement(mDocument); 
     39  if (root == NULL) 
     40    if (mRootNodeName != NULL) { 
     41      root = xmlNewDocNode(mDocument,NULL,mRootNodeName,NULL); 
     42    } else { 
     43      root = xmlNewDocNode(mDocument,NULL,(xmlChar*)"__dba_for_replace",NULL); 
     44    }; 
     45  xmlDocSetRootElement(mDocument,root); 
     46  if ((mRootNodeName != NULL) && (xmlStrcmp(mRootNodeName,root->name))) 
     47    throw DataException("Wrong root node name"); 
     48  updateEncoding(); 
     49  mRootNode = xmlDocGetRootElement(mDocument); 
    3350}; 
    3451 
     
    8097XMLArchive::close() { 
    8198  if (mDocument != NULL) { 
    82     write(); 
    83     xmlFreeDoc(mDocument); 
     99    if (!mFilename.empty()) { 
     100      write(); 
     101      xmlFreeDoc(mDocument); 
     102    }; 
    84103    mDocument = NULL; 
    85104  }; 
  • trunk/dba/dba/xmlarchive.h

    r166 r172  
    4343    virtual void open(const char* pOpenStr); 
    4444    /** 
     45      Open already created document in memory. Archive will not take  
     46      ownership on this document. 
     47      @param pDocument libxml2 xmlDoc pointer to already created document 
     48    */ 
     49    virtual void open(xmlDocPtr pDocument); 
     50    /** 
    4551      Close archive and write xml document to file 
    4652    */ 
     
    6773    /** 
    6874      name of file where mDocument is serialized 
     75      If empty then mDocument is supplied by user 
    6976    */ 
    7077    std::string mFilename; 
  • trunk/wxdba/wxdba/xmlarchive.cpp

    r169 r172  
    3737  try { 
    3838    mHandle.open(pOpenStr.mb_str(wxConvFile)); 
     39  } catch (const dba::Exception& pEx) { 
     40    Exception::Rethrow(pEx); 
     41  }; 
     42}; 
     43 
     44void  
     45XMLArchive::Open(xmlDocPtr pDocument) { 
     46  try { 
     47    mHandle.open(pDocument); 
    3948  } catch (const dba::Exception& pEx) { 
    4049    Exception::Rethrow(pEx); 
  • trunk/wxdba/wxdba/xmlarchive.h

    r171 r172  
    1818    void AddNamespace(const wxString& pName, const wxString& pPrefix); 
    1919    void Open(const wxString& pOpenStr); 
     20    void Open(xmlDocPtr pDocument); 
    2021    bool IsOpen() const; 
    2122    XMLOStream GetOStream();