473,320 Members | 1,879 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,320 software developers and data experts.

How to write XML declaration with DOMWriter class Xerces-c

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 allows me to write the
according DOM tree to a given location using LocalFileFormatTarget().
Everything works fine except that I cant define and set a certain XML
declaration. The tutorial seems to provide an easy way to do this by
applying the setEncoding(), setVersion() or setStandalone() functions
to the according DOMDocument. But even after setting those parameters
as well as enabling the fgDOMXMLDeclaration() feature of the DOMWriter
nothing is written except one empty line at the beginning of the
document. What am I doing wrong???

The according code snippet is given below:

const XMLCh gLS[] = { chLatin_L, chLatin_S, chNull };
DOMImplementation* impl =
DOMImplementationRegistry::getDOMImplementation(gL S);
DOMWriter* theSerializer = ((DOMImplementationLS*)impl)-
>createDOMWriter();
if (theSerializer->canSetFeature(XMLUni::fgDOMXMLDeclaration,true) )
theSerializer->setFeature(XMLUni::fgDOMXMLDeclaration, true);

DOMDocument* doc;
doc = impl->createDocument(
0, // root element
namespaceURI.
XMLString::transcode("rootnode"),
// root element name
0); // document type
object(DTD).

doc->setEncoding(XMLString::transcode("UTF-8"));
doc->setVersion(XMLString::transcode("1.0"));

DOMNode* node = XMLwalker->getRoot(); //Set
Walker to Root node of the document
XMLFormatTarget *myFormTarget;
myFormTarget = new
LocalFileFormatTarget(written_XML_name.c_str()); //output to file
try{
theSerializer->writeNode(myFormTarget, *node);
}
catch.....

Any Help is appreciated as for my purposes the integration of the xml
declaration is compulsory!

Best regards,
Christian Eickhoff

Mar 5 '07 #1
3 9460
On 5 Mrz., 11:14, christian.eickh...@nt.uni-saarland.de wrote:
DOMNode* node = XMLwalker->getRoot(); //Set
Walker to Root node of the document
XMLFormatTarget *myFormTarget;
myFormTarget = new
LocalFileFormatTarget(written_XML_name.c_str()); //output to file
try{
theSerializer->writeNode(myFormTarget, *node);
Hi Christian!

You get the XML root here with XMLwalker->getRoot(); but not the root
of the DOM tree. DOMDocument is actually the root of your DOM. Try
replacing writeNode(myFormTarget, *node) with writeNode(myFormTarget,
*doc).

Regards spiff
http://www.spycomponents.com

Mar 5 '07 #2
On 5 Mrz., 14:15, "spiff" <s...@gmx.atwrote:
On 5 Mrz., 11:14, christian.eickh...@nt.uni-saarland.de wrote:
DOMNode* node = XMLwalker->getRoot(); //Set
Walker to Root node of the document
XMLFormatTarget *myFormTarget;
myFormTarget = new
LocalFileFormatTarget(written_XML_name.c_str()); //output to file
try{
theSerializer->writeNode(myFormTarget, *node);

Hi Christian!

You get the XML root here with XMLwalker->getRoot(); but not the root
of the DOM tree. DOMDocument is actually the root of your DOM. Try
replacing writeNode(myFormTarget, *node) with writeNode(myFormTarget,
*doc).

Regards spiffhttp://www.spycomponents.com
Hey spiff,

not the first time you helped me out!!! Thanks so much, good to have
versed experts like you! Now everything works fine =))..

With best regards,
Christian Eickhoff

Mar 5 '07 #3
On 5 Mrz., 16:02, christian.eickh...@nt.uni-saarland.de wrote:
not the first time you helped me out!!! Thanks so much, good to have
versed experts like you! Now everything works fine =))..

With best regards,
Christian Eickhoff
Christian,
fine that it is working now :-)

spiff

Mar 5 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jochen Daum | last post by:
Hi, Can someone confirm this problem: This works: var $x = array( "x" => "x". "y", "y" => "a".
1
by: Venkat | last post by:
Hi All, I am getting unusual compile errors when i declare a vector as a private member of a class in .h file, but if i declare the same in .cpp file inside the definition of a function which...
4
by: Ovidesvideo | last post by:
Just a quick question. If I declare functions in the class declaration as such: class myclass { public: void function(int &x) { x++; } };
2
by: flopbucket | last post by:
Hi, How can I forward declare a class that is in a different namespace? As a simple example: classs Foo { std::string *string; };
1
by: Jeremy S. | last post by:
I'm implementing logging via the TraceSource class and related TraceSwitch and TraceListeners classes. The TextWriterTraceListener does much of what I need. But it does not roll the log over at...
9
by: Andrew | last post by:
Hi, I see some people prefer to use in headers (where possible) class declaration: // B.h class A; class B {
2
by: Shahrin | last post by:
#include<iostream> using namespace std; class teacher; class student { int dept; public:
3
Fr33dan
by: Fr33dan | last post by:
I'm a long time Java guy trying to move to C++ but I keep getting this error that I can't seem to figure out. It must be something simple I'm missing but I can't find it by looking at examples. I...
0
by: Alex T | last post by:
A few months ago I asked about this, and it seems this issue is still not resolved, so I'm asking for your help. I want to write a date class that skips weekends and these holidays a. New Year,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.