473,386 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

DOMWriter does not read from memory

HI... I got this far with my source :

Expand|Select|Wrap|Line Numbers
  1.  
  2.     #include <xercesc/dom/deprecated/DOMParser.hpp>
  3.     #include <xercesc/util/PlatformUtils.hpp>
  4.     #include <xercesc/dom/DOM_Document.hpp>
  5.     #include <xercesc/dom/deprecated/DOM_DOMException.hpp>
  6.     #include <xercesc/dom/deprecated/DOM_Element.hpp>
  7.     #include <xercesc/dom/deprecated/DOM_Node.hpp>
  8.     //For backup test start
  9.     #include <xercesc/dom/DOM.hpp>
  10.     #include <xercesc/util/XMLString.hpp>
  11.     #include <xercesc/dom/DOMImplementation.hpp>
  12.     #include <xercesc/dom/DOMImplementationLS.hpp>
  13.     #include <xercesc/dom/DOMImplementationRegistry.hpp>
  14.     #include <xercesc/framework/StdOutFormatTarget.hpp>
  15.     //End
  16.     #include <string>
  17.     #include <sstream>
  18.     #include <stdexcept>
  19.     #include <list>
  20.     #include <iostream>
  21.     #include <locale.h>
  22.  
  23.  
  24.     using namespace std;
  25.  
  26.     XERCES_CPP_NAMESPACE_USE
  27.  
  28.  
  29.     int main(int argc, char* argv[]){
  30.  
  31.         setlocale(LC_ALL,NULL);
  32.         setlocale(LC_NUMERIC,"C");
  33.  
  34.         cout << "Starting program \n";
  35.         cout << "Initializing the DOM ... ";
  36.  
  37.         try{
  38.             //Initialize Xerces
  39.             XMLPlatformUtils::Initialize();
  40.             cout << " ok \n";
  41.         }
  42.         catch (const XMLException& toCatch) {
  43.             char* message = XMLString::transcode(toCatch.getMessage());
  44.             cout << " failed \n";
  45.             cout << "Error during initialization! :\n"
  46.                  << message << "\n";
  47.             XMLString::release(&message);
  48.             return 1;
  49.         }
  50.  
  51.         //Create parser
  52.         DOMParser oParser;
  53.  
  54.         cout << "Parsing the XML file ... ";
  55.  
  56.         try{
  57.             //Create the DOM treen and write it to memory
  58.             oParser.parse("test2.xml");
  59.             cout << " ok \n";
  60.         }
  61.         catch (const XMLException& toCatch) {
  62.             cout << " failed \n";
  63.             cout << "Exception message is: \n"
  64.                  << toCatch.getMessage()<< "\n";
  65.             return -1;
  66.         }
  67.         catch (const DOM_DOMException&) {
  68.             cout << " failed \n";
  69.             cout << "Error parsing file \n";
  70.             return -1;
  71.         }
  72.         catch (...) {
  73.             cout << " failed \n";
  74.             cout << "Unexpected Exception \n";
  75.             return -1;
  76.         }
  77.  
  78.         //Get the first Element in the XML file
  79.         DOM_Document oDoc=oParser.getDocument();
  80.  
  81.         //access the tree
  82.         if(oDoc!=0){
  83.             DOM_Element oRoot=oDoc.getDocumentElement();
  84.             cout << "oRoot= " << &oRoot <<endl;
  85.  
  86.             if(oRoot!=0){
  87.                 DOM_Node oNode=oRoot.getFirstChild();
  88.  
  89.                 while(oNode!=0){
  90.                     if(oNode.getNodeType()==DOM_Node::ELEMENT_NODE){
  91.                         DOM_Element oNodeEle=(DOM_Element&)oNode;
  92.  
  93.                         if(oNodeEle.getNodeName().equals(DOMString("Port"))){
  94.                             DOMString oAttrVal=oNodeEle.getAttribute(DOMString("nr"));
  95.  
  96.                             if(oAttrVal.length()>0){
  97.                                 char* pcLocal=oAttrVal.transcode();
  98.                                 int nPort=atoi(pcLocal);
  99.  
  100.                                 cout << "Port: " << nPort << endl;
  101.  
  102.                                 //Clear variable
  103.                                 delete[]pcLocal;
  104.                             };
  105.                         }
  106.  
  107.                         else if(oNodeEle.getNodeName().equals(DOMString("Data"))){
  108.                             DOMString oAttrVal=oNodeEle.getAttribute(DOMString("path"));
  109.  
  110.                             if(oAttrVal.length()>0){
  111.                                 char* pcLocal=oAttrVal.transcode();
  112.  
  113.                                 cout << "Data: " << pcLocal <<endl;
  114.  
  115.                                 //clear variable
  116.                                 delete[]pcLocal;
  117.                             };
  118.                         };
  119.  
  120.                     };
  121.  
  122.                     //Go to next entry
  123.                     oNode=oNode.getNextSibling();
  124.  
  125.                 };
  126.  
  127.             }else{
  128.                 cout << "Root node not found" << endl;
  129.             };
  130.  
  131.         }else{
  132.             cout << "Document not found" << endl;
  133.         };
  134.  
  135.  
  136.         cout << "Programm finished" << endl;
  137.  
  138.  
  139.  
  140.  
  141.         //Writing to file try start
  142.  
  143.         const XMLCh gLS[]={ chLatin_L, chLatin_S, chNull};
  144.         DOMImplementation* impl= DOMImplementationRegistry::getDOMImplementation(gLS);
  145.         DOMWriter* theSerializer=((DOMImplementationLS*)impl)->createDOMWriter();
  146.  
  147.         if(theSerializer->canSetFeature(XMLUni::fgDOMXMLDeclaration,true))
  148.             theSerializer->setFeature(XMLUni::fgDOMXMLDeclaration,true);
  149.  
  150.  
  151.         DOMDocument* doc;
  152.         doc = impl->createDocument(0,XMLString::transcode("Config"),0);
  153.         doc->setEncoding(XMLString::transcode("UTF-8"));
  154.         doc->setVersion(XMLString::transcode("1.0"));
  155.  
  156.         DOMNode* node = (DOMDocument*)doc->getDocumentElement();
  157.         XMLFormatTarget *myFormTarget;
  158.         myFormTarget = new StdOutFormatTarget();
  159.  
  160.         try{
  161.             cout << endl;
  162.             theSerializer->writeNode(myFormTarget, *doc);
  163.             cout << endl << endl;
  164.         }
  165.         catch(...){
  166.             cout << "Fehler am Ende!" << endl;
  167.         }
  168.  
  169.  
  170.  
  171.         theSerializer->release();
  172.  
  173.         //Writing to file try end
  174.  
  175.         return 0;
  176.  
  177.     }
  178.  
  179.  
  180.  

and all I get as output is:

<?xml version="1.0" encoding="iso-8859-1"?><Config />


but the file looks like:

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="iso-8859-1"?>
  2. <Config>
  3. <Port nr="50000" />
  4. <Data path="."/>
  5. </Config>
  6.  

What am I doing wrong?? Any idea??

Thanks in advance
Jun 4 '07 #1
1 1670
dorinbogdan
839 Expert 512MB
I posted a link to your question in the C/C++ forum too.
Jun 4 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Simon | last post by:
Hi, I'm trying to serialize an XML document to a file using XERCES-C++ 2.1.0 . The Document contains an internal DTD. The DTD contains some elements with default values like the following...
38
by: Martin Marcher | last post by:
Hi, I've read several questions and often the answer was 'C knows nothing about .' So if C knows that little as some people say, what are the benefits, I mean do other languages know more...
20
by: Jonas | last post by:
Hi, I'm 99 % sure that Standard C guarantees to do a memory move inside realloc() in case the new, returned memory block (address) is different than the original one. Can any C expert confirm...
24
by: David Mathog | last post by:
If this: int i,sum; int *array; for(sum=0, i=0; i<len; i++){ sum += array; } is converted to this (never mind why for the moment):
5
by: Barry Anderberg | last post by:
I'm using a tool by Sci-Tech called the .NET Memory Profiler. We have a massive .NET/C# application here and it has been exhibiting memory leak behavior for some time. Attempting to remedy the...
51
by: Tony Sinclair | last post by:
I'm just learning C#. I'm writing a program (using Visual C# 2005 on WinXP) to combine several files into one (HKSplit is a popular freeware program that does this, but it requires all input and...
5
by: mkaushik | last post by:
Hi everyone, Im just starting out with C++, and am curious to know how "delete <pointer>", knows about the number of memory locations to free. I read somewhere that delete frees up space...
3
by: christian.eickhoff | last post by:
Hello Everyone, currently I am implementing a solution to write individually created XML data to a file using c++ and Xerces-c 2.7.0 library. Therefore I am making use of DOMWriter class which...
19
by: Angus | last post by:
I have a socket class CTestClientSocket which I am using to simulate load testing. I create multiple instances of the client like this: for (int i = 0; i < 5; i++) { CTestClientSocket* pTemp...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.