0
함수 변환기()는 구문 분석 된 xsl 스트림을 입력으로 받아 들여 출력 문자열을 반환합니다. 이 기능을 개선 할 수 있습니까? 들어오는 문자열을 캐시 할 수 있습니까? 제안 사항을 보내 주시면 감사하겠습니다. 대신 그 원료 C의Apache XalanC++을 사용하여 XSL 변환 개선 libaray
int converter(char *xslInput,char *htmlOutput) { int theResult=-1; int i=0; char c; char xmlbuf[100] = {'\0'}; char xmlbuf1[]="<?xml version=\"1.0\" encoding=\""; char xmlbuf2[]="\"?><a></a>"; char default_encoding[]="iso-8859-1"; char final_encoding[15]; char *encoding = NULL;
strcpy(final_encoding,default_encoding);
strcpy(xmlbuf,xmlbuf1);
strcat(xmlbuf,final_encoding);
strcat(xmlbuf,xmlbuf2);
XALAN_USING_STD(cerr)
XALAN_USING_STD(cout)
XALAN_USING_STD(endl)
XALAN_USING_STD(ofstream)
XALAN_USING_STD(ostrstream)
XALAN_USING_STD(istrstream)
XALAN_USING_STD(ostrstream)
XALAN_USING_XERCES(XMLPlatformUtils)
XALAN_USING_XALAN(XalanTransformer)
ostrstream theOutput;
// 2. Initialize Xerces and Xalan
XMLPlatformUtils::Initialize();
XalanTransformer::initialize();
{
// 3. Create a XalanTransformer
XalanTransformer theXalanTransformer;
// Our input streams...
istrstream theXMLStream(xmlbuf, strlen(xmlbuf));
istrstream theXSLStream(xslInput, strlen(xslInput));
ostrstream theOutput;
// 4. Prepare the input and output sources
XALAN_USING_XALAN(XSLTInputSource)
XALAN_USING_XALAN(XSLTResultTarget)
// 5. Perform the transformation
theResult = theXalanTransformer.transform(&theXMLStream, &theXSLStream, theOutput);
if(theResult != 0)
{
cerr << "StreamTransform Error: \n" << theXalanTransformer.getLastError()
<< endl
<< endl;
}
else
{
theOutput << '\0';
strcpy(htmlOutput, theOutput.str());
cout << "Result of Transformation is SUCCESS\n" ;
}
}
// 5. Shutdown the transformation thingy...
XalanTransformer::terminate();
XalanTransformer::ICUCleanUp();
XMLPlatformUtils::Terminate();
return theResult;
}
예를 들어 왜 어쨌든 final_encoding이 필요합니까? –
대기 ...이 코드가 작동합니까? transform()에 대한 호출에 대해 묻습니다. ** ostrstream **을 전달하여 출력을 처리하지만 API에 따라 예상 매개 변수는 ** XSLTResultTarget ** 객체입니다. – IcedDante
또한 transform()의 세 번째 매개 변수에도 '&'연산자가 있어야합니다. theXalanTransformer.transform (& theXMLStream, & theXSLStream, & theOutput); – IcedDante