Hi,
I am a new user to Xalan-C++. I want to apply xsl transformation to xml
stored in a buffer and get the output into a buffer. The
StreamTransform.cpp example reads from a buffer and writes output to a
stream. I want to make this write to a buffer. I saw some discussion about
this in this group and tried following the advice of extending
Callbackhandler. But I am getting many compilation errors. Has anyone
already done this? Could you please post your code? Any help will be
greatly appreciated.
This is what I tried:
//Declaration of wrapper class
XALAN_USING_XALAN(XalanOutputStream)
class xalan_string_stream:public XalanOutputStream{
private:
char *output;
char *buffer;
unsigned cursor;
public:
xalan_string_stream(MemoryManagerType
XALAN_DEFAULT_CONSTRUCTOR_MEMORY_MGR,
size_type theBufferSize = eDefaultBufferSize,
size_type theTranscoderBlockSize = eDefaultTranscoderBlockSize,
bool fThrowTranscodeException = true){
buffer=new char[1024];
}
~xalan_string_stream(){}
void writeData (const char *input, size_type length){
bcopy(input,buffer,length);
}
void doFlush (){
}
char *get_result(){
return buffer;
}
};
//usage inside main
istrstream theXMLStream(theInputDocument,
strlen(theInputDocument));
istrstream theXSLStream(theStyleSheet, strlen(theStyleSheet));
XALAN_USING_XALAN(XalanDOMString)
XALAN_USING_XALAN(XalanOutputStreamPrintWriter)
XALAN_USING_XALAN(XSLTResultTarget)
XALAN_USING_XALAN(XSLTInputSource)
XSLTInputSource inputSource(&theXSLStream);
inputSource.setSystemId(XalanDOMString("foo").c_str());
const xalan_string_stream *outputStream = new xalan_string_stream();
XalanOutputStreamPrintWriter *printWriter=new
XalanOutputStreamPrintWriter((XalanOutputStream &)outputStream, false);
XSLTResultTarget target(printWriter);
theResult = theXalanTransformer.transform(&theXMLStream,
inputSource,target);
//compilation error obtained
BufferTransform.cpp:40: base `xalanc_1_10::XalanOutputStream' with only
non-default constructor in class without a constructor
BufferTransform.cpp:54: ISO C++ forbids defining types within return type
BufferTransform.cpp:54: destructors must be member functions
BufferTransform.cpp:54: return type specification for destructor invalid
BufferTransform.cpp:56: type specifier omitted for parameter `size_type'
BufferTransform.cpp:56: syntax error before `)' token
BufferTransform.cpp: In function `void writeData(...)':
BufferTransform.cpp:57: `input' undeclared (first use this function)
BufferTransform.cpp:57: (Each undeclared identifier is reported only once
for each function it appears in.)
BufferTransform.cpp:57: `buffer' undeclared (first use this function)
BufferTransform.cpp:57: `length' undeclared (first use this function)
BufferTransform.cpp: At global scope:
BufferTransform.cpp:66: syntax error before `}' token
BufferTransform.cpp: In function `int transform(const char*, char*)':
BufferTransform.cpp:155: ISO C++ forbids declaration of
`xalan_string_stream'
with no type
BufferTransform.cpp:155: uninitialized const `xalan_string_stream'
BufferTransform.cpp:155: syntax error before `*' token
BufferTransform.cpp:157: `outputStream' undeclared (first use this
function)
make: *** [all] Error 1
thanks,
Nithya