Re: [xml] Exslt Transform with Params
- From: "Buchcik, Kasimier" <k buchcik 4commerce de>
- To: "Alex Neblett" <alexneblett01 yahoo com>
- Cc: xml gnome org
- Subject: Re: [xml] Exslt Transform with Params
- Date: Tue, 20 Jun 2006 10:43:21 +0200
Hi,
I can't comment on memory leaks in your app, but you could
use xmlMemDisplay() or xmlMemoryDump() to check for leaks.
Additionally I call Libxslt's initialization and finalization
functions:
xmlInitParser();
xsltInit();
... my code ...
xsltCleanupGlobals();
xmlCleanupParser();
xmlMemDisplay(stdout);
Regards,
Kasimier
-----Original Message-----
From: xml-bounces gnome org [mailto:xml-bounces gnome org] On
Behalf Of Alex Neblett
Sent: Tuesday, June 20, 2006 7:35 AM
To: xml gnome org
Subject: [xml] Exslt Transform with Params
Hello,
I have written the following c++ code to allow me to use do
exslt transforms
using libxml2/libxslt/libexslt from C# using .NET 1.1 on the Windows
platform.
In doing so, I based it upon the api's and sample code.
I would like to make sure that it does not memory leak and that I have
called the api's appropriately and not forgotten anything.
The code presently works. I am open to any and all
suggestions for improving
it.
Kind Regards,
Alex
// exslt.h: Headers for the DLL application.
// The following ifdef block is the standard way of creating
macros which
make exporting
// from a DLL simpler. All files within this DLL are compiled with the
EXSLT_EXPORTS
// symbol defined on the command line. this symbol should not
be defined on
any project
// that uses this DLL. This way any other project whose
source files include
this file see
// EXSLT_API functions as being imported from a DLL, whereas
this DLL sees
symbols
// defined with this macro as being exported.
#ifdef EXSLT_EXPORTS
#define EXSLT_API __declspec(dllexport)
#else
#define EXSLT_API __declspec(dllimport)
#endif
EXSLT_API int ClearParms(void);
EXSLT_API int AddParams (char* paramname, char* paramvalue);
EXSLT_API int exslttransform(const char* xmlstring, const
char* xsltstring,
const char* resultfile);
EXSLT_API int exslttransformxmlfile(const char* xmlstring, const char*
xsltstring, const char* resultfile);
// exslt.c: Defines the entry point for the DLL application.
//
#include "exslt.h"
#include <string.h>
#include <libxml/xmlmemory.h>
#include <libxml/debugXML.h>
#include <libxml/HTMLtree.h>
#include <libxml/xmlIO.h>
#include <libxml/DOCBparser.h>
#include <libxml/xinclude.h>
#include <libxml/catalog.h>
#include <libxslt/xslt.h>
#include <libxslt/xsltInternals.h>
#include <libxslt/transform.h>
#include <libxslt/xsltutils.h>
#include <libexslt/exslt.h>
#include <libexslt/exsltconfig.h>
#include <libexslt/exsltexports.h>
#include <libexslt/libexslt.h>
char params[100][512];
int nbparams = 0;
EXSLT_API int AddParams(char* paramname, char* paramvalue)
{
int i;
int k;
i = 0;
k = 0;
// Make paramvalue ASCII and end with NULL
while (paramvalue[i] != '\0')
{
if (paramvalue[i] < 128 && paramvalue[i] > 0)
{
paramvalue[k] = paramvalue[i];
k++;
}
i++;
}
while (k < i)
{
paramvalue[k] = '\0';
k++;
}
i = 0;
// pass paramname into params and null rest of that string
while (paramname[i] != '\0')
{
params[nbparams][i] = paramname[i];
i++;
}
nbparams++;
i = 0;
// pass paramvalue into params and null rest of that string
while (paramvalue[i] != '\0')
{
params[nbparams][i] = paramvalue[i];
i++;
}
nbparams++;
return (1);
}
EXSLT_API int ClearParms(void)
{
int i, j;
nbparams = 0;
for (i = 0; i < 100; i++)
{
for (j = 0; j < 512; j++)
{
params[i][j] = '\0';
}
}
return (0);
}
EXSLT_API int exslttransform(const char* xmlstring, const
char* xsltstring,
const char* resultfile)
{
xsltStylesheetPtr cur = NULL;
xmlDocPtr doc, res, dxsl;
int i;
const char *zparams[100 + 1];
int nbzparams;
nbzparams = 0;
i = 0;
while (i < nbparams)
{
zparams[i] = strdup((const char *)¶ms[i]);
i++;
}
zparams[i] = NULL;
exsltRegisterAll();
xmlInitParser();
xmlSubstituteEntitiesDefault(1);
dxsl = xmlParseMemory(xsltstring, (int)strlen(xsltstring));
cur = xsltParseStylesheetDoc(dxsl);
doc = xmlParseMemory(xmlstring, (int)strlen(xmlstring));
res = xsltApplyStylesheet(cur, doc, zparams);
xsltSaveResultToFilename((const char*) resultfile, res, cur, 0);
xsltFreeStylesheet(cur);
//for (i = 0;i < nbparams;i++)
//xmlFree(zparams[i]);
xmlFreeDoc(res);
xmlFreeDoc(doc);
xsltCleanupGlobals();
xmlCleanupParser();
return(0);
}
EXSLT_API int exslttransformxmlfile(const char* xmlfile, const char*
xsltstring, const char* resultfile)
{
xsltStylesheetPtr cur = NULL;
xmlDocPtr doc, res, dxsl;
int i;
const char *zparams[100 + 1];
int nbzparams;
nbzparams = 0;
i = 0;
while (i < nbparams)
{
zparams[i] = strdup((const char *)¶ms[i]);
i++;
}
zparams[i] = NULL;
exsltRegisterAll();
xmlInitParser();
xmlSubstituteEntitiesDefault(1);
dxsl = xmlParseMemory(xsltstring, (int)strlen(xsltstring));
cur = xsltParseStylesheetDoc(dxsl);
doc = xmlParseFile(xmlfile);
res = xsltApplyStylesheet(cur, doc, zparams);
xsltSaveResultToFilename((const char*) resultfile, res, cur, 0);
xsltFreeStylesheet(cur);
//for (i = 0;i < nbparams;i++)
//xmlFree(zparams[i]);
xmlFreeDoc(res);
xmlFreeDoc(doc);
xsltCleanupGlobals();
xmlCleanupParser();
return(0);
}
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
xml gnome org
http://mail.gnome.org/mailman/listinfo/xml
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]