7 Replies Latest reply: Oct 15, 2012 3:09 PM by Lucas Vogel RSS

    In  Berkeley DB XML 2.4.16, data with <![CDATA[]]> is not updated in db.

    966125
      Hi,

      I have an application which is runing 2.3.10 properly. When i am upgrading to 2.4.10. update node for <![CDATA[]]> is failed it only update the data. I want <![CDATA[data]]> to be inserted into DB like 2.3.10.

      Here is the sample example:

      #include <string.h>
      #include <dbxml/DbXml.hpp>
      #include <unistd.h>
      using namespace std;
      using namespace DbXml;

      int main()
      {
      try{
      DbEnv* vl_dbEnv = NULL;
      vl_dbEnv = new DbEnv(0);
      u_int32_t vl_dbEnvFlags = (
      DB_CREATE|
      DB_INIT_MPOOL|
      DB_INIT_TXN|
      DB_INIT_LOCK|
      DB_INIT_LOG|
      DB_RECOVER|
      DB_THREAD
      );
      string vl_sdbDataDir("MyDB/");
      vl_dbEnv->open(vl_sdbDataDir.c_str(), vl_dbEnvFlags, 0);

      u_int32_t vl_dbxmlFlags = (
      DBXML_ALLOW_EXTERNAL_ACCESS|
      DBXML_ADOPT_DBENV
      );
      XmlManager* vl_dbMgr = new XmlManager(vl_dbEnv, vl_dbxmlFlags);
      u_int32_t vl_Containerflags = (
      DBXML_TRANSACTIONAL|
      DB_THREAD|
      DBXML_INDEX_NODES);
      // XmlTransaction *vl_pTxn = &vl_Txn;
      string vl_ContainerName("MyContainer");
      XmlContainer::ContainerType vl_ContainerType = XmlContainer::NodeContainer;
      XmlContainer* vl_pcontainer_ = NULL;
      string vl_content("MyDoc1");
      XmlDocument vl_doc;
      if(!vl_dbMgr->existsContainer(vl_ContainerName)){
      printf("\n Container Not exists Create a MyContainer");
      XmlTransaction vl_Txn = vl_dbMgr->createTransaction();
      XmlContainer vl_XmlContainer = vl_dbMgr->createContainer(vl_Txn, vl_ContainerName,vl_Containerflags,vl_ContainerType);
      vl_pcontainer_ = new XmlContainer(vl_XmlContainer);
      vl_doc = vl_dbMgr->createDocument();
      vl_doc.setName("MyDoc");
      XmlUpdateContext vl_uc = vl_dbMgr->createUpdateContext();
      string content("<__><![CDATA[server_1]]><type><![CDATA[Server_1]]></type><Password><![CDATA[bk1984]]></Password></__>");
      vl_doc.setContent(content);
      vl_pcontainer_->putDocument(vl_Txn, vl_doc, vl_uc);
      vl_doc.setName("MyDoc1");
      vl_uc = vl_dbMgr->createUpdateContext();
      content = "<__><![CDATA[server_1]]><type><![CDATA[Server_1]]></type><Password><![CDATA[bk1984]]></Password></__>";
      vl_doc.setContent(content);
      vl_pcontainer_->putDocument(vl_Txn, vl_doc, vl_uc);
      vl_Txn.commit();
      }
      else{
      printf("\n Container MyContainer Exists Open the Container");
      vl_pcontainer_ = new XmlContainer(vl_dbMgr->openContainer(vl_ContainerName,vl_Containerflags));
      printf("\n Getting the Doc from Container");
      XmlTransaction vl_RdTxn = vl_dbMgr->createTransaction((u_int32_t)0/*67108864DB_DEGREE_2*/);
      vl_doc = vl_pcontainer_->getDocument(vl_RdTxn,vl_content,DB_RMW);
      vl_doc.getContent(vl_content);
      printf("\n MyDoc1 ContentsBefore Update:%s",vl_content.c_str());
      XmlModify vl_modify = vl_dbMgr->createModify();

      XmlQueryExpression vl_RmqueryExp;
      XmlQueryContext vl_qRmcontxt = vl_dbMgr->createQueryContext();
      vl_RmqueryExp = vl_dbMgr->prepare("/__/Key", vl_qRmcontxt);
      vl_modify.addRemoveStep(vl_RmqueryExp);

      XmlQueryExpression vl_AddqueryExp;
      XmlQueryContext vl_qAddcontxt = vl_dbMgr->createQueryContext();
      vl_AddqueryExp = vl_dbMgr->prepare("/__", vl_qAddcontxt);

      vl_modify.addAppendStep (vl_AddqueryExp,XmlModify::Element, "Key","<![CDATA[08B]]>");

      XmlQueryContext qc = vl_dbMgr->createQueryContext();
      XmlUpdateContext uc = vl_dbMgr->createUpdateContext();
      XmlValue vl_xmldocValue(vl_doc);
      unsigned int modifications = vl_modify.execute(vl_RdTxn, vl_xmldocValue, qc, uc);
      vl_RdTxn.commit();
      }

      vl_content = "MyDoc1";
      vl_doc = vl_pcontainer_->getDocument(/*vl_RdTxn,*/vl_content,0);
      vl_doc.getContent(vl_content);
      printf("\n Contents of My Doc1:%s",vl_content.c_str());
      printf("\n Closing the Application");
      delete vl_pcontainer_;
      delete vl_dbMgr;
      //delete vl_dbEnv;
      }
      catch (DbException& ex) {
      }
      catch (XmlException& ex) {
      }


      return 0;
      }


      In DB XML 2.3.10 the out put is

      #./testUpdateContainer

      Container Not exists Create a MyContainer
      Contents of My Doc1:<__><![CDATA[server_1]]><type><![CDATA[Server_1]]></type><Password><![CDATA[bk1984]]></Password></__>
      Closing the Application
      # ./testUpdateContainer

      Container MyContainer Exists Open the Container
      Getting the Doc from Container
      MyDoc1 ContentsBefore Update:<__><![CDATA[server_1]]><type><![CDATA[Server_1]]></type><Password><![CDATA[bk1984]]></Password></__>
      Contents of My Doc1:<__><![CDATA[server_1]]><type><![CDATA[Server_1]]></type><Password><![CDATA[bk1984]]></Password><Key><![CDATA[08B]]></Key></__>
      Closing the Application

      Here after update *<Key><![CDATA[08B]]></Key>*.

      where as in* DB XML 2.4.16*,

      # ./testUpdateContainer

      Container Not exists Create a MyContainer
      Contents of My Doc1:<__><![CDATA[server_1]]><type><![CDATA[Server_1]]></type><Password><![CDATA[bk1984]]></Password></__>
      Closing the Application

      #./testUpdateContainer

      Container MyContainer Exists Open the Container
      Getting the Doc from Container
      MyDoc1 ContentsBefore Update:<__><![CDATA[server_1]]><type><![CDATA[Server_1]]></type><Password><![CDATA[bk1984]]></Password></__>
      Contents of My Doc1:<__><![CDATA[server_1]]><type><![CDATA[Server_1]]></type><Password><![CDATA[bk1984]]></Password><Key>08B</Key></__>
      Closing the Application

      Here after update *<Key>08B</Key>*.

      In 2.4.16, Key attribute value is not updated with <![CDATA[08B]]>. It might be escaping the text.

      How can I update Key value with CDATA tag.

      Thanks in advance.

      Bijaya

      Edited by: 963122 on Oct 4, 2012 2:58 AM

      Edited by: 963122 on Oct 4, 2012 2:59 AM