On 07/03/2001,

> Hello!
>
> At the company I work for, we use CGI's (programmed in C) and basically
> every CGI produces as an outcome a HTML, now we want to move forward and
> start generating XML instead then parse it and then generate the HTML to
> send to the browser. Thats why we are trying XALAN to see if thats the
right
> move for us.
>
> I have been trying a very simple example using the C API interface that
you
> provide with XALANTRANSFORMERCAPI.H but have not been lucky to get it to
> work. Could you please tell me what I am doing wrong or if I am missing
some
> important and decisive feature or something or  that I am just misusing
> it?!?
>
> Let me describe my example/code so you get a better idea of the whole
> scenario.
>
> In principle, the core of the CGI will generate an XML which is written
to a
> string (or a file and for the sake of the example I have used the foo.xml
> and the foo.xsl sample that you provide) then pass it to the
> XalanTransformToData and get the result back on a stream pointer (the
char**
> argument of it).
>
>   char** ptrString;

This should be:

    char* ptrString;

>   XalanHandle *xalan = NULL;
>   int resultCode = 0;
>
>      // Initialise the XALAN and create the TRANSFORMER
>
>     XalanInitialize();
>
>     xalan = CreateXalanTransformer();
>
>       // Parsing and then analysing the XML file using the XSL file as
well.
>
>     resultCode = XalanTransformToData("foo.xml","foo.xsl",
&ptrString,xalan);

I don't know why your compiler is not complaining about passing in the
address of a char** here.

>
>      // Handling the outcome
>
>     if(!resultCode)  {
>       printf("%s<br>\n", *ptrString);
>     }
>     else printf("The parsing was unsuccessful.\n");

You can get the last error and see what it is:

    if(!resultCode)  {
        printf("%s<br>\n", *ptrString);
    }
    else
    {
        const XalanCCharPtr  theError = XalanGetLastError(xalan);

        printf("The parsing was unsuccessful.  The error message was:
%s\n", theError);
    }
>
>       // clean memory and close down Xalan.
>
>     XalanFreeData(*ptrString);

This should be:

        XalanFreeData(ptrString);

>     DeleteXalanTransformer(xalan);
>     XalanTerminate();

You should be aware that once you call XalanTerminate(), the current
process will no longer be able to use the C API.  This is due to a
limitation with the Xerces parser.

This is often a problem with things like CGI, which spawn processes to
handle requests.  It's not very efficient to constantly initalize and
terminate Xalan.  Do you know for a fact that your CGI framework _is_
spawning processes?  If it's not, you'll need to figure out a way to
initialize Xalan _once_, before you start processing requests.  Otherwise,
your code should be fine, although it's not optimal.

>
> Even when trying with foo.xml and foo.xsl no good result is obtained, I
get
> a -1 value from  resultCode. what does it mean? (have searched the whole
> site for error codes to no avail).

There is no interesting meaning to the error codes (they correspond to
broad classes of exceptions in the C++ code), which is why you should call
XalanGetLastError()and see what the error text is.

> Have previously tried allocating memory for ptrstring and passing it to
the
> function without using & but then an internal server error was the
result.
> Do i need to allocate memory for it or u do it within the function
> XalanTransformToData?? &ptrString is the right usage??

You definitely should not do this, as the transformer will just overwrite
the pointer and you'll end up with a leak.

> I hope you can help me out or point me in the right direction as to where
I
> can find out about all this.
>
> Thanks a lot for your time,
>
> Rigo.

You're welcome.

Try making the corrections I've indicated and see what happens.  If you
still get an error, see what the error is from the transfomer.  If you
still can't figure out what's wrong, post the error message.

In the meantime, I'm going to write and check in a sample application that
uses various aspects of the C API.  Perhaps that will help make things more
clear.

Dave


==============================================================================

This message has been checked for all known viruses by MessageLabs.
This message is intended for the stated recipients only and may be
confidential. Opinions expressed in this email do not necessarily reflect
the opinions of GlobePost Travel or Travelselect.com. If you are not the
intended recipient of this message, please notify the sender immediately.
==============================================================================



Reply via email to