The DOMWriter can actually be told directly to output UTF-16 (or any other known encoding) :
DOMWriter *dw = impl->createDOMWriter();
encNameStr = XMLString::transcode("UTF-8");
dw->setEncoding(encNameString);
XMLCh* xcXML = dw->writeToString(*doc);
char *cXML = XMLString::transcode(xcXML);
delete dw;Should work.
Cheers,
BerinMilan Tomic wrote:
That is exactly what I did. The only problem is that it took me about 2 minutes on my PC (P4 2.6 GHz, 512 MB RAM) to write 1,5 MB in ostringstream. So, I've done this:
DOMWriter *dw = impl->createDOMWriter();
XMLCh* xcXML = dw->writeToString(*doc);
char *cXML = XMLString::transcode(xcXML);
delete dw;
It works fine, but there is "UTF-16" specifier in the first line of my XML document:
<?xml version="1.0" encoding="UTF-16" standalone="no" ?>
I've tried this (from templatesign.cpp), to replace "UTF-16" with "UTF-8":
encNameStr = XMLString::transcode("UTF-8");
aNode = doc->getFirstChild();
if (aNode->getNodeType() == DOMNode::ENTITY_NODE)
{
((DOMEntity *)aNode)->setEncoding(encNameStr);// never comes here.
}
But, it doesn't work. It never steps into "if".
Thank you.
-----Original Message----- *From:* Scott Cantor [mailto:[EMAIL PROTECTED] *Sent:* Monday, December 01, 2003 5:31 PM *To:* [EMAIL PROTECTED] *Subject:* RE: DOMNode to char*
Just write a link between the serializer and an ostream&. Then you
can dump to cout or to a ostrstream or ostringstream and extract a
char* from that.
-- Scott
-----Original Message-----
*From:* Milan Tomic [mailto:[EMAIL PROTECTED]
*Sent:* Monday, December 01, 2003 11:29 AM
*To:* [EMAIL PROTECTED]
*Subject:* DOMNode to char*
Berin,
I have one (beginner) question. It is more about Xerces. I can't get DOMNode (and all its children nodes) as char*. In templatesign.exe there is a way to send DOMNode to standard output:
DOMNode *doc; ... cout << doc;
But, I dont wont to put doc in stdout, I'd like to put it into char* variable. Do you know how? Example:
char* result = doc->GetXML();// there is no GetXML() function
I wrote this:
DOMWriter *dw = impl->createDOMWriter(); XMLCh* xcXML = dw->writeToString(*doc); char *cXML = XMLString::transcode(xcXML); delete dw;
But, when save result (cXML) in file I got an error because this is UTF-16 encoding and I need UTF-8.
Thank you.
