[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: [xml] Access violations with xmlDocDumpMemory
- From: "Buchcik, Kasimier" <k buchcik 4commerce de>
- To: "Andreas Tscharner" <andreas tscharner metromec ch>
- Cc: xml gnome org
- Subject: Re: [xml] Access violations with xmlDocDumpMemory
- Date: Tue, 11 Jul 2006 11:36:25 +0200
Hi,
I forgot to attach the code... here it comes.
Kasimier
> -----Original Message-----
> From: xml-bounces gnome org [mailto:xml-bounces gnome org] On
> Behalf Of Andreas Tscharner
> Sent: Tuesday, July 11, 2006 9:49 AM
> To: xml gnome org
> Subject: [xml] Access violations with xmlDocDumpMemory
>
> Hello World,
>
> I'm creating a new document in the memory. The document is well formed
> and if I save it to the file system using
> xmlSave[Format]FileEnc, I get
> the exspected result. The problem is that I need the document in a
> string, so I thought to use one of xmlDocDump*Memory* family. The
> document size does not matter, I tried from 4k to 2.5MiB...
> But now I'm having a problem with xmlDocDumpMemory in all
> flowers (e.g.
> with or without *Format and *Enc). No matter which of these
> functions I
> call, I always get an access violation.
> Are there any preconditions I need to fulfill to make it work?
>
> I'm using the Windows version 2.6.24 from Igor (also tried
> 2.6.22+, but
> the same results) with Delphi/Pascal bindings.
>
> Any ideas?
I digged out some old and obsolete Delphi code which tried to
serialize the result of an XSLT transformation with
xmlDocDumpMemoryEnc(). Although the code is wrong - it
should use LibXSLT's serialization functions - it still might be
of some use for you.
Cheers,
Kasimier
procedure TDomNode.transformNode(const stylesheet: IDomNode; var output: DomString);
var
doc: xmlDocPtr;
styleDoc: xmlDocPtr;
outputDoc: xmlDocPtr;
styleNode: xmlNodePtr;
tempXSL: xsltStylesheetPtr;
encoding: widestring;
length1: longint;
CString: PChar;
len: integer;
meta: widestring;
doctype: integer;
element: xmlNodePtr;
begin
doc := fXmlNode.doc;
styleNode := GetXmlNode(stylesheet);
styleDoc := styleNode.doc;
if (styleDoc = nil) or (doc = nil) then
exit;
tempXSL := xsltParseStyleSheetDoc(styleDoc);
if tempXSL = nil then
exit;
// mark the document as stylesheetdocument;
// it holds additional information, so a different free method must
// be used
(stylesheet.ownerDocument as IDomInternal).set_FtempXSL(tempXSL);
// kb2003-09-16: This applies the stylesheet always to the document
outputDoc := xsltApplyStylesheet(tempXSL, doc, nil);
if outputDoc = nil then
exit;
doctype := outputDoc.type_;
element := xmlDocGetRootElement(outputDoc);
encoding := outputDoc.encoding;
xmlDocDumpMemoryEnc(outputDoc, CString, @length1, outputDoc.encoding);
output := CString;
// free the document as a string is returned, and not the document
xmlFreeDoc(outputDoc);
// if the document is of type plain-text or html
if (element = nil) or (doctype = 13) then begin
//cut the leading xml header
len := pos('>', output) + 2;
output := copy(output, len, length1 - len);
end;
xmlFree(CString);
end;
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]