使用ApacheXalanc++libaray改进XSL转换

使用ApacheXalanc++libaray改进XSL转换,c++,c,xalan,C++,C,Xalan,函数转换器接受解析后的xsl流作为输入,并返回输出字符串。 我可以改进这个功能吗? 我可以缓存传入字符串吗? 如有任何建议,将不胜感激 一件事是使用了太多的局部变量,例如char xmlbuf1、char xmlbuf2等。此外,您可以使用std::string而不是原始的c样式数组吗?例如,为什么您仍然需要最终编码?等等。。。这个代码还能用吗?我在问关于转变的电话。它传递OSRTStream来处理输出,但根据API,预期参数是XSLTResultTarget对象。此外,我相当确定要转换的第三个

函数转换器接受解析后的xsl流作为输入,并返回输出字符串。 我可以改进这个功能吗? 我可以缓存传入字符串吗? 如有任何建议,将不胜感激


一件事是使用了太多的局部变量,例如char xmlbuf1、char xmlbuf2等。此外,您可以使用std::string而不是原始的c样式数组吗?

例如,为什么您仍然需要最终编码?等等。。。这个代码还能用吗?我在问关于转变的电话。它传递OSRTStream来处理输出,但根据API,预期参数是XSLTResultTarget对象。此外,我相当确定要转换的第三个参数也应该有“&”操作符:thexalantTransformer.transform&theXMLStream,&theXSLStream,&theOutput;
 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;
    }