Nithya Nirmal Vijayakumar wrote:
> I am a new user to Xerces-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 tried modifying this to write to a buffer. I followed
> the same pattern defined in the example for converting the buffer to a
> stream.

Hi Nithya,

in short, you need to write a special XalanOutputStream derivate that 
handles buffers (I called it xalan_string_stream). With this class, you 
can proceed stylesheet processing as usual.

XALAN_USING_XALAN(XalanOutputStream)

class xalan_string_stream: public XalanOutputStream{
        char *output;
        char *buffer;
        unsigned cursor;
public:
        xalan_string_stream();
        virtual ~xalan_string_stream();
        void writeData (const char *input, size_type length);
        void doFlush ();
        char *get_result();
};


The abstract XalanOutputStream methods have to be implemented:
        void writeData (const char *input, size_type length);
        void doFlush ();

Finally, get_result() returns the filled buffer.

You need to constrain your class to work with
1. a fixed size buffer (member buffer)
2. a variable (growing) buffer (member output)
and you need to check that writeData(.) does not overrun your buffer.

HTH,
                        Axel

Reply via email to