Функция converter () принимает проанализированный поток xsl в качестве входных данных и возвращает строку вывода.
Могу ли я улучшить эту функцию?
Могу ли я кешировать входящие строки?
Любое предложение будет оценено.
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;
}