Hi Sascha,
you are not seeing the XML PI because you are
serializing the root node, instead of the DOMDocument node.
However, if you use writeToString the encoding
will always be UTF-16 (as the returned XMLCh
buffer is Unicode). Furthermore, converting the
returned string using transcode will convert it
to the current system encoding, that could be
something different from the ISO-8859-1 you are expecting.
The proper way to generate a ISO-8859-1 buffer is by using writeNode:
MemBufFormatTarget destination;
writer->setEncoding(X("ISO-8859-1"));
bool retVal = writer->writeNode(&destination, *doc);
XMLByte * iso8859buffer=destination.getRawBuffer();
Hope this helps,
Alberto
At 09.55 23/06/2006 +0200, Sascha Bahl wrote:
Hello list!
i´ve a problem with the Xerces. How can i write
my DOM out to a string includes with the xml declaration in the art:
<?xml version="1.0" encoding="ISO-8859-1"?>
I have wrote the following codesnipped:
DOMImplementation* impl =
DOMImplementationRegistry::getDOMImplementation( X("LS") );
XERCES_CPP_NAMESPACE_QUALIFIER DOMDocument* doc = impl->createDocument();
doc->setEncoding( X("UTF-8") );
doc->setVersion( X("1.0") );
DOMElement* xml_root_node = doc->createElement( X("ERROR") );
doc->appendChild( xml_root_node );
// Das XML-Dokument in einen String schreiben
DOMWriter* writer
= static_cast<DOMImplementationLS*>(impl)->createDOMWriter( );
// Einen Fehler-Handler registrieren
DOMErrorHandler* errHandler = (DOMErrorHandler*) new HandlerBase();
writer->setErrorHandler( errHandler );
const XMLCh* xmlch_xml_doc = writer->writeToString( *xml_root_node );
const char* str_xml_doc = XMLString::transcode( xmlch_xml_doc );
XMLString::release( (XMLCh**)&xmlch_xml_doc );
The only output is "<ERROR/>" without the xml
declaration. What´s wrong? What can i do?
Greetings
Sascha