After searching google and looking into the xerces example I realized that for
stdout I have to use a StdOutFormatTarget. The xml is written to stdout now.
Unfortunately the xerces parser doesn't escape all xml special characters. So I
have two questions. Any help is really appreciated.
- Why isn't the umlaut ü converted to ü?
- Why isn't the quotation sign converted to " by the transcoder?
The OS is still Red Hat Enterprise, Xerces 2.7.
[[output (ü is distorted by shell?)]]
debug xData [München -> <- "'], eaten [16], charSizes [], xRet [16], xOut [M]
<?xml version="1.0" encoding="UTF-8" standalone="no"
?><xtestroot><test>München -> <- "'</test></xtestroot>
[[code]]
utf8Transcoder =
XMLPlatformUtils::fgTransService->makeNewTranscoderFor("ISO-8859-1",
failReason, 16*1024);
DOMImplementation* _impl2 =
DOMImplementationRegistry::getDOMImplementation(XMLString::transcode("LS"));
DOMDocument* _doc2 = _impl2->createDocument(0,
XMLString::transcode("xtestroot"), 0);
DOMElement* _rootElem2 = _doc2->getDocumentElement();
//convert content
char* xData = "München -> <- \"'";
XMLCh* xOut = new XMLCh[ strlen(xData) * 6 + 1 ];
int xRet = utf8Transcoder->transcodeFrom( (const XMLByte*)xData, strlen(xData),
xOut, strlen(xData) * 6 + 1, eaten, charSizes );
printf("debug xData [%s], eaten [%d], charSizes [%s], xRet [%d], xOut [%s]\n",
xData, eaten, charSizes, xRet, xOut );
//create xml
DOMElement* nextNode2 = _doc2->createElement(XMLString::transcode("test"));
_rootElem2->appendChild(nextNode2);
DOMText* nodeData2 = _doc2->createTextNode( xOut );
nextNode2->appendChild(nodeData2);
//write xml
DOMWriter* theSerializer2 = ((DOMImplementationLS*)_impl2)->createDOMWriter();
XMLFormatTarget *myFormatTarget = new StdOutFormatTarget();
theSerializer2->writeNode( myFormatTarget, *_doc2 );
printf("\n");fflush(stdout);
With kind regards,
Mario Freimann